Code:
uses
Windows;
{...}
type
TShutdownWindowsType = (swtShutdown, swtShutdownPowerOff, swtRestart, swtLogoff);
function ShutdownWindows (aType: TShutdownWindowsType): Boolean;
{...}
function ShutdownWindows (aType: TShutdownWindowsType): Boolean;
const
cSE_SHUTDOWN_NAME = 'SeShutdownPrivilege';
cFlagValue: Array [TShutdownWindowsType] Of UINT = (
EWX_SHUTDOWN, EWX_SHUTDOWN or EWX_POWEROFF, EWX_REBOOT, EWX_LOGOFF
);
var
OSVersionInfo: TOSVersionInfo;
hToken: THandle;
hProcess: THandle;
TokenPriv: TTokenPrivileges;
ReturnLength: DWORD;
begin
Result := False;
// Die Windowsversion holen
OSVersionInfo.dwOSVersionInfoSize := SizeOf (OSVersionInfo);
if not GetVersionEx (OSVersionInfo) then
Exit;
// Prüfen ob Windows NT
if OSVersionInfo.dwPlatformId = VER_PLATFORM_WIN32_NT then
begin
hProcess := GetCurrentProcess;
if not OpenProcessToken (hProcess, TOKEN_ADJUST_PRIVILEGES, hToken) then
Exit;
if not LookupPrivilegeValue (nil, cSE_SHUTDOWN_NAME, TokenPriv.Privileges[0].Luid) then
Exit;
TokenPriv.PrivilegeCount := 1;
TokenPriv.Privileges [0].Attributes := SE_PRIVILEGE_ENABLED;
if not AdjustTokenPrivileges (
hToken, False, TokenPriv, 0,
PTokenPrivileges (nil)^, ReturnLength
)
then
Exit;
CloseHandle (hToken);
end;
ShutdownWindows := ExitWindowsEx (cFlagValue [aType], $FFFFFFFF);
end;
Könnte dir helfen :]