기술자료/델파이팁
시스템종료, 재시작, Windows 9x/NT/Me/2000/XP
theF
2012. 4. 19. 11:17
..
function MyExitWindows(RebootParam: Longword): Boolean; var TTokenHd: THandle; TTokenPvg: TTokenPrivileges; cbtpPrevious: DWORD; rTTokenPvg: TTokenPrivileges; pcbtpPreviousRequired: DWORD; tpResult: Boolean; const SE_SHUTDOWN_NAME = 'SeShutdownPrivilege'; begin if Win32Platform = VER_PLATFORM_WIN32_NT then begin tpResult := OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, TTokenHd); if tpResult then begin tpResult := LookupPrivilegeValue(nil, SE_SHUTDOWN_NAME, TTokenPvg.Privileges[0].Luid); TTokenPvg.PrivilegeCount := 1; TTokenPvg.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED; cbtpPrevious := SizeOf(rTTokenPvg); pcbtpPreviousRequired := 0; if tpResult then Windows.AdjustTokenPrivileges(TTokenHd, False, TTokenPvg, cbtpPrevious, rTTokenPvg, pcbtpPreviousRequired); end; end; Result := ExitWindowsEx(RebootParam, 0); end; // Example to shutdown Windows: procedure TForm1.Button1Click(Sender: TObject); begin MyExitWindows(EWX_POWEROFF or EWX_FORCE); end; // Example to reboot Windows: procedure TForm1.Button1Click(Sender: TObject); begin MyExitWindows(EWX_REBOOT or EWX_FORCE); end; // Parameters for MyExitWindows()
출처 : 한국 델파이 개발자 동호회
http://www.delphi.co.kr/?document_srl=157263&act=trackback&key=d5f