Desligar windows 2000

Delphi

08/04/2003

Alguém tem o código para
desligar o windows 2000?

quem sober, me envia um e-mail

birilo.nilo@ig.com.br


Anonymous

Anonymous

Curtidas 0

Respostas

Manoeljr

Manoeljr

08/04/2003

Caro amigo, desligar o windows95,98,ME é realmente simples porém para desligar o windows2000 ou XP você tem que antes ajustar os privilégios para poder ter direito de para realizar a tarefa. Eu criei uma função que uso em alguns programas que funciona muito bem para o windows2000 e XP. Segue abaixo a função:

Declare essa variavel como global
Fonte:BOOLEAN;{True=ATX - False=AT}

function Desliga: Integer;
var
rc: Integer;
pid: THandle;
hToken: THandle;
tmpLUID: TLUIDAndAttributes;
tkp, tkpNewButIgnored: TTokenPrivileges;
BufLen: DWORD;
begin
Result:=0;
pid:=GetCurrentProcess;

OpenProcessToken(pid,TOKEN_ADJUST_PRIVILEGES + TOKEN_QUERY,hToken);
LookupPrivilegeValue(nil,´SeShutdownPrivilege´, tmpLUID.LUID);
with tkp do
begin
PrivilegeCount := 1;
Privileges[0].Luid := tmpLUID.Luid;
Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
end;
AdjustTokenPrivileges(hToken,False,tkp,Sizeof(tkpNewButIgnored),tkpNewButIgnored, BufLen);

Sleep(1000);
if fonte=True then
if ExitWindowsEx({EWX_FORCE + EWX_SHUTDOWN} EWX_POWEROFF, 0) = True then Exit
else
if ExitWindowsEx({EWX_FORCE + }EWX_SHUTDOWN, 0) = True then Exit;

rc:= GetLastError;
Result:=1;
end;

Para usar é muito simples veja o Código para uso no Botão

procedure TForm1.Button1Click(Sender: TObject);
begin
Fonte:=true;//para Fontes ATX e False Para Fontes AT
Desliga;
end;

Espero ter ajudado,

Manoel Pedro Jr
Nápoles Team


GOSTEI 0
POSTAR