Como desligar o Windows 2000 via programação ?

06/12/2003

0

Alguém sabe como desligar o Windows 2000 pelo Delphi?

Os comandos abaixo só funcionam do Windows 95, 98:

{ Reinicia o Windows }
ExitWindowsEx(EWX_REBOOT, 0);

{ Desliga o Windows }
ExitWindowsEx(EWX_SHUTDOWN, 0);

??? :?:

[i:7bdb4a0fd8]Título editado. Digite em minúsculas. Leia as [url=http://delphiforum.icft.com.br/forum/viewtopic.php?t=6689&sid=076f77d4f6ae95d738e630e0812e94e9][u:7bdb4a0fd8]Regras de Conduta[/u:7bdb4a0fd8][/url]. (marcelo.c - Moderador)[/i:7bdb4a0fd8]


Rennpr

Rennpr

Responder

Posts

06/12/2003

Maicongabriel

{===============================================================================
Retorna se o OS é de Plataforma NT
===============================================================================}
function WinNT : Boolean;
begin if Win32Platform = VER_PLATFORM_WIN32_NT then
Result := True
else Result := False;
end;
{==============================================================================}


{===============================================================================
ShutDownWindows, 0 - Desliga Rapido, 1 - Desliga, 2 - Reinicia, 3 - LogOff, 4 - Force
===============================================================================}
function ShutDownWindows(Flag: Word) : Boolean;
var
TokenPriv : TTokenPrivileges;
Tamanho : DWord;
HToken : THandle;
begin
Case Flag of
0 : Flag := EWX_FORCE + EWX_POWEROFF;
1 : Flag := EWX_SHUTDOWN;
2 : Flag := EWX_REBOOT;
3 : Flag := EWX_LOGOFF;
4 : Flag := EWX_FORCE;
end;

if WinNT then
begin
OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES,HToken);
LookUpPrivilegeValue(NIL, ´SeShutdownPrivilege´,
TokenPriv.Privileges[0].Luid);
TokenPriv.PrivilegeCount := 1;
TokenPriv.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
Tamanho := 0;
AdjustTokenPrivileges(HToken, FALSE, TokenPriv, 0, PTokenPrivileges(NIL)^, Tamanho);
CloseHandle(HToken);
end;
Result := ExitWindowsEx(Flag, 0);
end;
{==============================================================================}


Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar