опубликован 02-11-2001 23:54 MSK
А НТ и не будет пахать!
В НТ вот так:function GrantShutdownAccess: boolean;
var
hToken: THandle;
lpVersionInformation: TOSVersionInfo;
tkp: TTokenPrivileges;
RetLen: DWORD;
PreviousState: TTokenPrivileges;
begin
lpVersionInformation.dwOSVersionInfoSize := SizeOf(lpVersionInformation);
Result := GetVersionEx(lpVersionInformation);
// Get a token for this process.
if (lpVersionInformation.dwPlatformId = VER_PLATFORM_WIN32_NT) then begin
// Running on NT so need to change privileges
// function OpenProcessToken(ProcessHandle: THandle; DesiredAccess: DWORD;
// var TokenHandle: THandle): BOOL; stdcall;
if not OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then begin
Result := False; exit;
end;
// Get the LUID for shutdown privilege
//function LookupPrivilegeValue(lpSystemName, lpName: PChar;
// var lpLuid: TLargeInteger): BOOL; stdcall;
Result := LookupPrivilegeValue( Nil, 'SeShutdownPrivilege',
tkp.Privileges[0].Luid);
if not Result then Exit;
PreviousState := tkp;
tkp.PrivilegeCount := 1; // one privilege to set
tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
// Get shutdown privilege for this process.
//function AdjustTokenPrivileges(TokenHandle: THandle;
// DisableAllPrivileges: BOOL;
// const NewState: TTokenPrivileges; BufferLength: DWORD;
// var PreviousState: TTokenPrivileges; var ReturnLength: DWORD): BOOL; stdcall;
if not(AdjustTokenPrivileges(hToken, FALSE, tkp, SizeOf(PreviousState), PreviousState, RetLen)) then begin
Result := False;
Exit;
end;
end;
Result := True;
end;
procedure RebootWindows;
begin
if GrantShutdownAccess then begin
ExitWindowsEx(EWX_REBOOT, 0);
end;
end;