WWW.ИСХОДНИКИ.РУ cpp.sources.ru
java.sources.ru web.sources.ru soft.sources.ru
jdbc.sources.ru asp.sources.ru api.sources.ru

  Форум на исходниках
  Delphi
  А как выключить комьютер?

СПРОСИТЬ  ОТВЕТИТЬ
профайл | регистрация | faq

Автор Тема:   А как выключить комьютер?
Drozd опубликован 27-10-2001 00:39 MSK   Click Here to See the Profile for Drozd   Click Here to Email Drozd  
Есть функция для этого?
Chief опубликован 28-10-2001 15:52 MSK     Click Here to See the Profile for Chief  Click Here to Email Chief     
смотри в хелпе функцию ExitWindowsEx
Alone God опубликован 02-11-2001 14:05 MSK     Click Here to See the Profile for Alone God  Click Here to Email Alone God     
Обалденно работает с флагом операции EWX_LOGOFF - все умирают, а приложение остаётся. За окном ввода пароля. Под НТ не проверял.
XOR опубликован 02-11-2001 23:54 MSK     Click Here to See the Profile for XOR  Click Here to Email XOR     
А НТ и не будет пахать!
В НТ вот так:

function GrantShutdownAccess: boolean;
var
hToken: THandle;
lpVersionInformation: TOSVersionInfo;
tkp: TTokenPrivileges;
RetLen: DWORD;
PreviousState: TTokenPrivileges;
begin
lpVersionInformation.dwOSVersionInfoSize := SizeOf(lpVersionInformation);
Result := GetVersionEx(lpVersionInformation);
// Get a token for this process.
if (lpVersionInformation.dwPlatformId = VER_PLATFORM_WIN32_NT) then begin
// Running on NT so need to change privileges
// function OpenProcessToken(ProcessHandle: THandle; DesiredAccess: DWORD;
// var TokenHandle: THandle): BOOL; stdcall;
if not OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then begin

Result := False; exit;
end;
// Get the LUID for shutdown privilege
//function LookupPrivilegeValue(lpSystemName, lpName: PChar;
// var lpLuid: TLargeInteger): BOOL; stdcall;
Result := LookupPrivilegeValue( Nil, 'SeShutdownPrivilege',
tkp.Privileges[0].Luid);
if not Result then Exit;
PreviousState := tkp;
tkp.PrivilegeCount := 1; // one privilege to set
tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;

// Get shutdown privilege for this process.
//function AdjustTokenPrivileges(TokenHandle: THandle;
// DisableAllPrivileges: BOOL;
// const NewState: TTokenPrivileges; BufferLength: DWORD;
// var PreviousState: TTokenPrivileges; var ReturnLength: DWORD): BOOL; stdcall;
if not(AdjustTokenPrivileges(hToken, FALSE, tkp, SizeOf(PreviousState), PreviousState, RetLen)) then begin
Result := False;
Exit;
end;
end;
Result := True;
end;

procedure RebootWindows;
begin
if GrantShutdownAccess then begin
ExitWindowsEx(EWX_REBOOT, 0);
end;
end;

СПРОСИТЬ  ОТВЕТИТЬ
Перейти:


E-mail | WWW.ИСХОДНИКИ.RU

Powered by: Ultimate Bulletin Board, Freeware Version 5.10a
Purchase our Licensed Version- which adds many more features!
© Infopop Corporation (formerly Madrona Park, Inc.), 1998 - 2000.