unit StandbyWindows_Unit;
interface
uses
Windows;
function StandbyWindows: Boolean;
implementation
const
SE_SHUTDOWN_NAME = '
SeShutdownPrivilege';
// -----------------------------------------------------------------------------
function StandbyWindows: Boolean;
var
OSVersionInfo: TOSVersionInfo;
hToken: THandle;
hProcess: THandle;
TokenPriv: TTokenPrivileges;
ReturnLength: DWORD;
begin
Result := False;
OSVersionInfo.dwOSVersionInfoSize := SizeOf(OSVersionInfo);
if not GetVersionEx(OSVersionInfo)
then
Exit;
case OSVersionInfo.dwPlatformId
of
VER_PLATFORM_WIN32_NT:
begin
hProcess := GetCurrentProcess;
if not OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES, hToken)
then
Exit;
if not LookupPrivilegeValue(
nil, SE_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;
{end VER_PLATFORM_WIN32_NT}
end;
{end case}
Result := SetSystemPowerState(True, False);
end;
{end function}
// -----------------------------------------------------------------------------
end.