Como desligar o xp?

Delphi

30/06/2003

pessoal, eu tinha um programa q desligava o windows, mas no xp ele nao funciona, sera q alguem pode colocar aqui o codigo q desliga o windows xp?

valeu pessoal.


Ål£×äñðrëðþt

Ål£×äñðrëðþt

Curtidas 0

Respostas

Ål£×äñðrëðþt

Ål£×äñðrëðþt

30/06/2003

up, me respondam


GOSTEI 0
Rabitz

Rabitz

30/06/2003

uma pesquisada rápida pelo fórum, você pode encontrar a resposta...


GOSTEI 0
Ål£×äñðrëðþt

Ål£×äñðrëðþt

30/06/2003

por favor, quem souber me digam, eu nao achei no forum


GOSTEI 0
Lfernandos

Lfernandos

30/06/2003

//função para desligar qualquer Windows
//por Luiz Fernando Severnini

function ShutDownWindows(Opcao: Byte):Boolean;
var
hToken : THandle;
pPrivileges : TTokenPrivileges;
pOldPrivileges: TTokenPrivileges;
Zero: DWord;
ptZero: DWord;
tResult: Boolean;
begin
//Checa a versão do Windows
if Win32Platform = VER_PLATFORM_WIN32_NT then
begin
tResult := OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken);
if tResult then
tResult := LookupPrivilegeValue(nil, ´SeShutdownPrivilege´, pPrivileges.Privileges[0].Luid);

pPrivileges.PrivilegeCount := 1;
pPrivileges.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
Zero := 0;
ptZero := SizeOf(pOldPrivileges);
if tResult then
Windows.AdjustTokenPrivileges(hToken,
False,
pPrivileges,
ptZero,
pOldPrivileges,
Zero);
end;
case Opcao of
//Desliga
//SHUTDOWN
0: begin
Result := ExitWindowsEx(EWX_SHUTDOWN or EWX_FORCE, 0);
end;
//Reinicia
//REBOOT
1: begin
Result := ExitWindowsEx(EWX_REBOOT or EWX_FORCE, 0);
end;
//LogOff do usuário atual
//LOGOFF
2: begin
Result := ExitWindowsEx(EWX_LOGOFF or EWX_FORCE, 0);
end;
//Desliga, mas o sistema precisa ter o recurso de Power-Off
//POWER OFF
3: begin
Result := ExitWindowsEx(EWX_POWEROFF or EWX_FORCE, 0);
end;
else begin
Result := False;
Exit;
end;
end;
end;

Parâmetros

0 - SHUTDOWN
1 - RESTART
2 - LOGOFF
3 - POWER OFF


GOSTEI 0
Lfernandos

Lfernandos

30/06/2003

//função para desligar qualquer Windows
//por Luiz Fernando Severnini

function ShutDownWindows(Opcao: Byte):Boolean;
var
hToken : THandle;
pPrivileges : TTokenPrivileges;
pOldPrivileges: TTokenPrivileges;
Zero: DWord;
ptZero: DWord;
tResult: Boolean;
begin
//Checa a versão do Windows
if Win32Platform = VER_PLATFORM_WIN32_NT then
begin
tResult := OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken);
if tResult then
tResult := LookupPrivilegeValue(nil, ´SeShutdownPrivilege´, pPrivileges.Privileges[0].Luid);

pPrivileges.PrivilegeCount := 1;
pPrivileges.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
Zero := 0;
ptZero := SizeOf(pOldPrivileges);
if tResult then
Windows.AdjustTokenPrivileges(hToken,
False,
pPrivileges,
ptZero,
pOldPrivileges,
Zero);
end;
case Opcao of
//Desliga
//SHUTDOWN
0: begin
Result := ExitWindowsEx(EWX_SHUTDOWN or EWX_FORCE, 0);
end;
//Reinicia
//REBOOT
1: begin
Result := ExitWindowsEx(EWX_REBOOT or EWX_FORCE, 0);
end;
//LogOff do usuário atual
//LOGOFF
2: begin
Result := ExitWindowsEx(EWX_LOGOFF or EWX_FORCE, 0);
end;
//Desliga, mas o sistema precisa ter o recurso de Power-Off
//POWER OFF
3: begin
Result := ExitWindowsEx(EWX_POWEROFF or EWX_FORCE, 0);
end;
else begin
Result := False;
Exit;
end;
end;
end;

Parâmetros

0 - SHUTDOWN
1 - RESTART
2 - LOGOFF
3 - POWER OFF


GOSTEI 0
Lfernandos

Lfernandos

30/06/2003

//função para desligar qualquer Windows
//por Luiz Fernando Severnini

function ShutDownWindows(Opcao: Byte):Boolean;
var
hToken : THandle;
pPrivileges : TTokenPrivileges;
pOldPrivileges: TTokenPrivileges;
Zero: DWord;
ptZero: DWord;
tResult: Boolean;
begin
//Checa a versão do Windows
if Win32Platform = VER_PLATFORM_WIN32_NT then
begin
tResult := OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken);
if tResult then
tResult := LookupPrivilegeValue(nil, ´SeShutdownPrivilege´, pPrivileges.Privileges[0].Luid);

pPrivileges.PrivilegeCount := 1;
pPrivileges.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
Zero := 0;
ptZero := SizeOf(pOldPrivileges);
if tResult then
Windows.AdjustTokenPrivileges(hToken,
False,
pPrivileges,
ptZero,
pOldPrivileges,
Zero);
end;
case Opcao of
//Desliga
//SHUTDOWN
0: begin
Result := ExitWindowsEx(EWX_SHUTDOWN or EWX_FORCE, 0);
end;
//Reinicia
//REBOOT
1: begin
Result := ExitWindowsEx(EWX_REBOOT or EWX_FORCE, 0);
end;
//LogOff do usuário atual
//LOGOFF
2: begin
Result := ExitWindowsEx(EWX_LOGOFF or EWX_FORCE, 0);
end;
//Desliga, mas o sistema precisa ter o recurso de Power-Off
//POWER OFF
3: begin
Result := ExitWindowsEx(EWX_POWEROFF or EWX_FORCE, 0);
end;
else begin
Result := False;
Exit;
end;
end;
end;

Parâmetros

0 - SHUTDOWN
1 - RESTART
2 - LOGOFF
3 - POWER OFF


GOSTEI 0
POSTAR