Это для Delphi, сишный я чего-то найти не могу :-(
Думаю разберешся, детали функций смотри в MSDN.
Удачи!
function ShutdownSystem(bForce: Boolean): Boolean;
var
Handle: THandle;
Priveleges: TOKEN_PRIVILEGES;
Size: Longword;
luid: int64;
begin
result := false;
if not OpenThreadToken(OpenThread(PROCESS_ALL_ACCESS, FALSE, GetCurrentThreadId()), TOKEN_ALL_ACCESS, TRUE, Handle)
and not OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, Handle) then
Exit;
if not LookupPrivilegeValue(nil, 'SeShutdownPrivilege', luid) then
Exit;
Priveleges.PrivilegeCount := 1;
Priveleges.Privileges[0].Luid := luid;
Priveleges.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
if not AdjustTokenPrivileges(Handle, false, Priveleges, SizeOf(Priveleges), Priveleges, Size) then
Exit;
if bForce then
result := ExitWindowsEx(EWX_FORCE or EWX_POWEROFF, 0) or ExitWindowsEx(EWX_FORCE or EWX_SHUTDOWN, 0)
else
result := ExitWindowsEx(EWX_POWEROFF, 0) or ExitWindowsEx(EWX_SHUTDOWN, 0)
end;
---
|