[SIZE=14] Может кто подскажет: "Как перезагрузить комп програмно, из Delphi в OS Windows XP".А то уж совсем сума сошёл. P.S.: Предпочтительно готовый участок кода!
// Enables or disables privileges debending on the bEnabled // Aktiviert oder deaktiviert Privilegien, abhangig von bEnabled
function NTSetPrivilege(sPrivilege: string; bEnabled: Boolean): Boolean; var hToken: THandle; TokenPriv: TOKEN_PRIVILEGES; PrevTokenPriv: TOKEN_PRIVILEGES; ReturnLength: Cardinal; begin Result := True; // Only for Windows NT/2000/XP and later. if not (Win32Platform = VER_PLATFORM_WIN32_NT) then Exit; Result := False;
// obtain the processes token if OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then begin try // Get the locally unique identifier (LUID) . if LookupPrivilegeValue(nil, PChar(sPrivilege), TokenPriv.Privileges[0].Luid) then begin TokenPriv.PrivilegeCount := 1; // one privilege to set
case bEnabled of True: TokenPriv.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED; False: TokenPriv.Privileges[0].Attributes := 0; end;
ReturnLength := 0; // replaces a var parameter PrevTokenPriv := TokenPriv;
// enable or disable the privilege
AdjustTokenPrivileges(hToken, False, TokenPriv, SizeOf(PrevTokenPriv), PrevTokenPriv, ReturnLength); end; finally CloseHandle(hToken); end; end; // test the return value of AdjustTokenPrivileges. Result := GetLastError = ERROR_SUCCESS; if not Result then raise Exception.Create(SysErrorMessage(GetLastError)); end;
begin NTSetPrivilege(SE_SHUTDOWN_NAME,True); ExitWindowsEx(EW_RESTARTWINDOWS,0); End;
Ну вот собственно.
Сообщение отредактировано: volvo - 5.11.2006 21:02