G
geoffrey
Unregistered / Unconfirmed
GUEST, unregistred user!
下面是我的代码,
发现ewx_poweroff和ewx_logoff效果是一样的,ewx_shutdown根本不执行。
procedure TForm1.ToolButton1Click(Sender: TObject);
begin
case radiogroup1.ItemIndex of
0: begin
if win32platform =ver_platform_win32_windows then
exitwindowsex(ewx_force+ewx_shutdown+ewx_poweroff,32);
if win32platform =ver_platform_win32_NT then
operatecomputer(ewx_poweroff); //ewx_logoff Ϊ¹Ø»ú
end;
1: begin
if win32platform =ver_platform_win32_windows then
exitwindowsex(ewx_force+ewx_shutdown+ewx_poweroff,32);
if win32platform =ver_platform_win32_NT then
operatecomputer(ewx_reboot); //ewx_reboot ΪÖØÆô
end;
2: begin
if win32platform =ver_platform_win32_windows then
exitwindowsex(ewx_force+ewx_shutdown+ewx_poweroff,32);
if win32platform =ver_platform_win32_NT then
operatecomputer(ewx_logoff); //ewx_logoff ΪעÏú
end;
end;
end;
procedure operatecomputer(statue:longword);
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(statue, 0)) then
begin
application.Terminate;
end;
end;
发现ewx_poweroff和ewx_logoff效果是一样的,ewx_shutdown根本不执行。
procedure TForm1.ToolButton1Click(Sender: TObject);
begin
case radiogroup1.ItemIndex of
0: begin
if win32platform =ver_platform_win32_windows then
exitwindowsex(ewx_force+ewx_shutdown+ewx_poweroff,32);
if win32platform =ver_platform_win32_NT then
operatecomputer(ewx_poweroff); //ewx_logoff Ϊ¹Ø»ú
end;
1: begin
if win32platform =ver_platform_win32_windows then
exitwindowsex(ewx_force+ewx_shutdown+ewx_poweroff,32);
if win32platform =ver_platform_win32_NT then
operatecomputer(ewx_reboot); //ewx_reboot ΪÖØÆô
end;
2: begin
if win32platform =ver_platform_win32_windows then
exitwindowsex(ewx_force+ewx_shutdown+ewx_poweroff,32);
if win32platform =ver_platform_win32_NT then
operatecomputer(ewx_logoff); //ewx_logoff ΪעÏú
end;
end;
end;
procedure operatecomputer(statue:longword);
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(statue, 0)) then
begin
application.Terminate;
end;
end;