执行一下下面的程序就可以了 procedure AdjustProcess; var VerInfo:TOSVersionInfo; hToken:THANDLE; tkp:TOKEN_PRIVILEGES; Nothing:Cardinal; begin VerInfo.dwOSVersionInfoSize:=SizeOf(VerInfo); GetVersionEx(VerInfo); if VerInfo.dwPlatformId=VER_PLATFORM_WIN32_NT then Begin OpenProcessToken(GetCurrentProcess,TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,hToken); LookupPrivilegeValue(nil,'SeShutdownPrivilege',tkp.Privileges[0].Luid); tkp.PrivilegeCount:= 1; tkp.Privileges[0].Attributes:= SE_PRIVILEGE_ENABLED; AdjustTokenPrivileges(hToken, FALSE, tkp, 0,nil, Nothing); End; end;
procedure Tfrmweb.windowsexitorreboot(flag: Integer); //关机、重起var VerInfo:TOSVersionInfo; hToken:THANDLE; tkp:TOKEN_PRIVILEGES; Nothing:Cardinal; begin VerInfo.dwOSVersionInfoSize:=SizeOf(VerInfo); GetVersionEx(VerInfo); if VerInfo.dwPlatformId=VER_PLATFORM_WIN32_NT then Begin OpenProcessToken(GetCurrentProcess,TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,hToken); LookupPrivilegeValue(nil,'SeShutdownPrivilege',tkp.Privileges[0].Luid); tkp.PrivilegeCount:= 1; tkp.Privileges[0].Attributes:= SE_PRIVILEGE_ENABLED; AdjustTokenPrivileges(hToken, FALSE, tkp, 0,nil, Nothing); End; case flag of 0 : begin ExitWindowsEx(EWX_POWEROFF,0); end ; 1 : begin ExitWindowsEx(EWX_REBOOT,0); end ; end ; end;
procedure AdjustProcess;
var
VerInfo:TOSVersionInfo;
hToken:THANDLE;
tkp:TOKEN_PRIVILEGES;
Nothing:Cardinal;
begin
VerInfo.dwOSVersionInfoSize:=SizeOf(VerInfo);
GetVersionEx(VerInfo);
if VerInfo.dwPlatformId=VER_PLATFORM_WIN32_NT then
Begin
OpenProcessToken(GetCurrentProcess,TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,hToken);
LookupPrivilegeValue(nil,'SeShutdownPrivilege',tkp.Privileges[0].Luid);
tkp.PrivilegeCount:= 1;
tkp.Privileges[0].Attributes:= SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, tkp, 0,nil, Nothing);
End;
end;
VerInfo:TOSVersionInfo;
hToken:THANDLE;
tkp:TOKEN_PRIVILEGES;
Nothing:Cardinal;
begin
VerInfo.dwOSVersionInfoSize:=SizeOf(VerInfo);
GetVersionEx(VerInfo);
if VerInfo.dwPlatformId=VER_PLATFORM_WIN32_NT then
Begin
OpenProcessToken(GetCurrentProcess,TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,hToken);
LookupPrivilegeValue(nil,'SeShutdownPrivilege',tkp.Privileges[0].Luid);
tkp.PrivilegeCount:= 1;
tkp.Privileges[0].Attributes:= SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, tkp, 0,nil, Nothing);
End;
case flag of
0 :
begin
ExitWindowsEx(EWX_POWEROFF,0);
end ;
1 :
begin
ExitWindowsEx(EWX_REBOOT,0);
end ;
end ;
end;