//MyExitWindows(EWX_SHUTDOWN); 抄的function IsWin9x: Boolean; var OsInfo: TOSVERSIONINFO; begin OsInfo.dwOSVersionInfoSize := sizeof(TOSVERSIONINFO); GetVersionEx(OsInfo); Result := (OsInfo.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS); end;function SetShutdownPrivilege(Enable: Boolean): Boolean; var PrevPrivileges: TTokenPrivileges; Privileges: TTokenPrivileges; Token: THandle; dwRetLen: DWord; begin Result := False; OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, Token); Privileges.PrivilegeCount := 1; if LookupPrivilegeValue(nil,'SeShutdownPrivilege', Privileges.Privileges[0].LUID) then begin if Enable then Privileges.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED else Privileges.Privileges[0].Attributes := 0; dwRetLen := 0; Result := AdjustTokenPrivileges(Token, False, Privileges, SizeOf(PrevPrivileges), PrevPrivileges, dwRetLen); end; CloseHandle(Token); end;procedure MyExitWindows(const P:Word); begin Application.Terminate; if IsWin9x then ExitWindowsEx(EWX_FORCE or P, 0) else begin SetShutdownPrivilege(True); ExitWindowsEx(EWX_FORCE or P, 0); SetShutdownPrivilege(False); end; end;
var
OsInfo: TOSVERSIONINFO;
begin
OsInfo.dwOSVersionInfoSize := sizeof(TOSVERSIONINFO);
GetVersionEx(OsInfo);
Result := (OsInfo.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS);
end;function SetShutdownPrivilege(Enable: Boolean): Boolean;
var
PrevPrivileges: TTokenPrivileges;
Privileges: TTokenPrivileges;
Token: THandle;
dwRetLen: DWord;
begin
Result := False;
OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, Token);
Privileges.PrivilegeCount := 1;
if LookupPrivilegeValue(nil,'SeShutdownPrivilege', Privileges.Privileges[0].LUID) then
begin
if Enable then
Privileges.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED
else
Privileges.Privileges[0].Attributes := 0;
dwRetLen := 0;
Result := AdjustTokenPrivileges(Token, False, Privileges, SizeOf(PrevPrivileges), PrevPrivileges, dwRetLen);
end;
CloseHandle(Token);
end;procedure MyExitWindows(const P:Word);
begin
Application.Terminate;
if IsWin9x then
ExitWindowsEx(EWX_FORCE or P, 0)
else
begin
SetShutdownPrivilege(True);
ExitWindowsEx(EWX_FORCE or P, 0);
SetShutdownPrivilege(False);
end;
end;
不会开启,关注。
就是NT系统下的线程标志问题(线程权限)