procedure reboot_computer; var hToken:THandle; tkp : TOKEN_PRIVILEGES; ReturnLength : DWord; begin if (not OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES or TOKEN_ALL_ACCESS or TOKEN_QUERY, hToken))then begin application.Terminate; end; LookupPrivilegeValue(nil,’SeShutdownPrivilege’,tkp.Privileges[0].Luid); tkp.PrivilegeCount := 1; tkp.Privileges[0].Attributes :=SE_PRIVILEGE_ENABLED; ReturnLength :=0; AdjustTokenPrivileges(hToken, FALSE, tkp, 0,nil,ReturnLength); if (GetLastError() <> ERROR_SUCCESS) then begin application.Terminate; end; if (not ExitWindowsEx(EWX_REBOOT, 0)) then begin application.Terminate; end; end; 看看这段,这是一段关机程序,对nt,2000都实用!
var
hToken:THandle;
tkp : TOKEN_PRIVILEGES;
ReturnLength : DWord;
begin if (not OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES or TOKEN_ALL_ACCESS or TOKEN_QUERY, hToken))then
begin
application.Terminate;
end;
LookupPrivilegeValue(nil,’SeShutdownPrivilege’,tkp.Privileges[0].Luid);
tkp.PrivilegeCount := 1;
tkp.Privileges[0].Attributes :=SE_PRIVILEGE_ENABLED;
ReturnLength :=0;
AdjustTokenPrivileges(hToken, FALSE, tkp, 0,nil,ReturnLength);
if (GetLastError() <> ERROR_SUCCESS) then
begin
application.Terminate;
end; if (not ExitWindowsEx(EWX_REBOOT, 0)) then
begin
application.Terminate;
end;
end;
看看这段,这是一段关机程序,对nt,2000都实用!