Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   API de Windows (https://www.clubdelphi.com/foros/forumdisplay.php?f=7)
-   -   urge. apagar windows XP (https://www.clubdelphi.com/foros/showthread.php?t=3260)

mrmanuel 29-08-2003 18:16:36

urge. apagar windows XP
 
Hola nuevamente.

Ya he escrito anteriormente respecto a este tema. y alguien, no recuerdo el nombre, me comentó que mirase én "trucomania".

de ahi saque esto:


ExitWindowsEx(EWX_SHUTDOWN,0);
ExitWindowsEx(EWX_FORCE,0);
ExitWindowsEx(EWX_LOGOFF,0);
ExitWindowsEx(EWX_POWEROFF,0);
ExitWindowsEx(EWX_REBOOT,0);


que funciona perfectamente para win 98 y me, pero para XP, nada de nada.

a alguien se le ocurre algo?

NickName 29-08-2003 19:47:47

Checa esto:


function TForm1.MyExitWindows(RebootParam: Longword): Boolean;
var
TTokenHd: THandle;
TTokenPvg: TTokenPrivileges;
cbtpPrevious: DWORD;
rTTokenPvg: TTokenPrivileges;
pcbtpPreviousRequired: DWORD;
tpResult: Boolean;
const
SE_SHUTDOWN_NAME = 'SeShutdownPrivilege';
begin
if Win32Platform = VER_PLATFORM_WIN32_NT then
begin
tpResult := OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,
TTokenHd);
if tpResult then
begin
tpResult := LookupPrivilegeValue(nil,
SE_SHUTDOWN_NAME,
TTokenPvg.Privileges[0].Luid);
TTokenPvg.PrivilegeCount := 1;
TTokenPvg.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
cbtpPrevious := SizeOf(rTTokenPvg);
pcbtpPreviousRequired := 0;
if tpResult then
Windows.AdjustTokenPrivileges(TTokenHd,
False,
TTokenPvg,
cbtpPrevious,
rTTokenPvg,
pcbtpPreviousRequired);
end;
end;
Result := ExitWindowsEx(RebootParam, 0);
end;

Se usa:

procedure TForm1.Button1Click(Sender: TObject);
begin
MyExitWindows(EWX_POWEROFF or EWX_FORCE);
end;

Espero te ayude en algo..

Saludos.

mrmanuel 31-08-2003 23:48:07

hola nuevamente

muchas gracias por tu ayuda. en Windows Xp funciona perfectamente.

gracias nuevamente

humexico.org 06-09-2003 05:09:24

A menudo lo podía hacer cuando empezaba a programar, desgraciadamente no guardé las rutinas ;)


La franja horaria es GMT +2. Ahora son las 23:48:33.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi