winnt中获得SE_SHUTDOWN_NAME特权procedure TForm1.Button1Click(Sender: TObject); var hToken,ReturnLength: Cardinal; MyTokenPrivileges: TOKEN_PRIVILEGES; begin ReturnLength := 0; Win32Check(OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,hToken)); Win32Check(LookupPrivilegeValue(nil,'SeShutdownPrivilege',MyTokenPrivileges.Privileges[0].Luid)); MyTokenPrivileges.PrivilegeCount := 1; // one privilege to set MyTokenPrivileges.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED; Win32Check(AdjustTokenPrivileges(hToken,false,MyTokenPrivileges,0,nil,ReturnLength)); Win32Check(CloseHandle(hToken)); Win32Check(ExitWindowsEx(EWX_POWEROFF + EWX_FORCEIFHUNG, 0)); end;
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(1, 0)) then begin application.Terminate; end; end; hehe,试试中吧
试试修改 if (not ExitWindowsEx(1, 0)) then begin application.Terminate; end; 中的1,来运行不同的关机选项
var
hToken,ReturnLength: Cardinal;
MyTokenPrivileges: TOKEN_PRIVILEGES;
begin
ReturnLength := 0; Win32Check(OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,hToken));
Win32Check(LookupPrivilegeValue(nil,'SeShutdownPrivilege',MyTokenPrivileges.Privileges[0].Luid));
MyTokenPrivileges.PrivilegeCount := 1; // one privilege to set
MyTokenPrivileges.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
Win32Check(AdjustTokenPrivileges(hToken,false,MyTokenPrivileges,0,nil,ReturnLength));
Win32Check(CloseHandle(hToken));
Win32Check(ExitWindowsEx(EWX_POWEROFF + EWX_FORCEIFHUNG, 0));
end;
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(1, 0)) then
begin
application.Terminate;
end;
end;
hehe,试试中吧
if (not ExitWindowsEx(1, 0)) then
begin
application.Terminate;
end;
中的1,来运行不同的关机选项