如何在程序中关闭WIN2000?(100分)

  • 主题发起人 主题发起人 ydsoftyyd
  • 开始时间 开始时间
Y

ydsoftyyd

Unregistered / Unconfirmed
GUEST, unregistred user!
如何在程序中关闭WIN2000?在WIN98中的方法好象不能在WIN2000中使用。
 
得用API函数控制,你查查,WIN2000的好多API和Win98不同
 
function SetPrivilege(sPrivilegeName: string;
bEnabled: Boolean): Boolean;
var
TPPrev,
TP : TTokenPrivileges;
Token :THandle;
dwRetLen : DWORD;
begin
result := False;
OpenProcessToken (GetCurrentProcess,
TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,
Token);
TP.PrivilegeCount := 1;
if LookupPrivilegeValue (nil, PChar (sPrivilegeName), TP.Privileges[0].LUID) then
begin
if bEnabled then
TP.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED
else
TP.Privileges[0].Attributes := 0;
dwRetLen := 0;
result := AdjustTokenPrivileges (
Token,
False,
TP,
SizeOf (TPPrev),
TPPrev,
dwRetLen);
end;
CloseHandle (Token);
end;
function WinExit (iFlags: integer) : Boolean;
begin
result := true;
if SetPrivilege ('SeShutdownPrivilege', true) then
begin
if (not ExitWindowsEx (iFlags, 0)) then
begin
// handle errors...
result := False
end;
SetPrivilege ('SeShutdownPrivilege', False)
end
else
begin
// handle errors...
result := False
end;
end;

procedure FormCreate(Sender: TObject);
begin
WinExit(EWX_POWEROFF + EWX_FORCE);
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
application.Terminate;
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
application.Terminate;
if (not ExitWindowsEx(EWX_REBOOT, 0)) then
application.Terminate;
end;
 
一个API不就行了
ExitWindowsEx()
或ExitWindows()
 
迟了半步,
 
多人接受答案了。
 
后退
顶部