Z
zhoufujin
Unregistered / Unconfirmed
GUEST, unregistred user!
下面代码为什么不能使win2k和winxp关机(win98可以)?
(关机进行到“您可以安全地关机了”,就停止了)
大家帮忙。
procedure Tform1.DoShutdown;
var
flgs: Cardinal;
tkp: _TOKEN_PRIVILEGES;
hdlTokenHandle: Cardinal;
tkpNewButIgnored: _TOKEN_PRIVILEGES;
lBufferNeeded: Cardinal;
timeDelay: Cardinal;
begin
flgs := 0;
flgs := flgs or EWX_FORCE or EWX_SHUTDOWN or EWX_PowerOff;
if Win32Platform = VER_PLATFORM_WIN32_NT then
begin
FillChar(tkp, sizeof(tkp), 0);
OpenProcessToken(GetCurrentProcess, (TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY), hdlTokenHandle);
LookupPrivilegeValue('', 'SeShutdownPrivilege', tkp.Privileges[0].Luid);
tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
tkp.PrivilegeCount := 1;
AdjustTokenPrivileges(hdlTokenHandle, False, tkp, Sizeof(TOKEN_PRIVILEGES), tkpNewButIgnored, lBufferNeeded);
Caption := 'SHUTDOWN';
timeDelay := 0;
if not InitiateSystemShutdown(nil, nil, timeDelay, LongBool(True), LongBool(False)) then AbortSystemShutdown(nil);
end else
begin
ExitWindowsEx(flgs, 0);
end;
end;
(关机进行到“您可以安全地关机了”,就停止了)
大家帮忙。
procedure Tform1.DoShutdown;
var
flgs: Cardinal;
tkp: _TOKEN_PRIVILEGES;
hdlTokenHandle: Cardinal;
tkpNewButIgnored: _TOKEN_PRIVILEGES;
lBufferNeeded: Cardinal;
timeDelay: Cardinal;
begin
flgs := 0;
flgs := flgs or EWX_FORCE or EWX_SHUTDOWN or EWX_PowerOff;
if Win32Platform = VER_PLATFORM_WIN32_NT then
begin
FillChar(tkp, sizeof(tkp), 0);
OpenProcessToken(GetCurrentProcess, (TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY), hdlTokenHandle);
LookupPrivilegeValue('', 'SeShutdownPrivilege', tkp.Privileges[0].Luid);
tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
tkp.PrivilegeCount := 1;
AdjustTokenPrivileges(hdlTokenHandle, False, tkp, Sizeof(TOKEN_PRIVILEGES), tkpNewButIgnored, lBufferNeeded);
Caption := 'SHUTDOWN';
timeDelay := 0;
if not InitiateSystemShutdown(nil, nil, timeDelay, LongBool(True), LongBool(False)) then AbortSystemShutdown(nil);
end else
begin
ExitWindowsEx(flgs, 0);
end;
end;