Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Trucos (https://www.clubdelphi.com/foros/forumdisplay.php?f=52)
-   -   Reiniciar, cambiar de usuario, apagar cualquier Windows (https://www.clubdelphi.com/foros/showthread.php?t=80671)

dec 01-07-2006 00:36:10

Reiniciar, cambiar de usuario, apagar cualquier Windows
 
No me peregunten que significa eso de privilegios, cambiar privilegios, y esas cosas, yo solo necesitaba un programa que me apagase el ordenador usando una unidad a control remoto; traduje un codigo visual basic que me pasaron y bueno a mi me funciona, actualmente tengo XP Profesional.

Código Delphi [-]
function GetCurrentProcess:THandle; stdcall; external 'kernel32.dll';

function OpenProcessToken(ProcessHandle:THandle;DesiredAccess:DWord;
  TokenHandle:PHandle):bool; stdcall;external 'advapi32.dll';

procedure EnableShutDown();
var
   hProc   : THandle;
   hToken  : THandle;
   mLUID   : int64;
   mPriv   : TOKEN_PRIVILEGES;
   mNewPriv: TOKEN_PRIVILEGES;
   mVar    : DWord;
begin
    hProc := GetCurrentProcess;
    OpenProcessToken(hProc,TOKEN_ADJUST_PRIVILEGES + TOKEN_QUERY,@hToken);
    LookupPrivilegeValue(Pchar(''),Pchar('SeShutdownPrivilege'), mLUID);
    mPriv.PrivilegeCount := 1;
    mPriv.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
    mPriv.Privileges[0].Luid := mLUID;
    mVar := 4 + (12 * mNewPriv.PrivilegeCount);
    AdjustTokenPrivileges(hToken, False, mPriv, 4 + 12 * mPriv.PrivilegeCount, mNewPriv,mVar)
end;

function IsWinNT():Boolean;
var
   myOS:OSVERSIONINFO;
begin
    myOS.dwOSVersionInfoSize:=sizeof(myOS);
    GetVersionEx(myOS);
    IsWinNT:=(myOS.dwPlatformId = VER_PLATFORM_WIN32_NT)
end;

procedure ShutDownNT(Force:Boolean);
var
   Flags  : Longint;
begin
    Flags := EWX_SHUTDOWN;
    If Force Then Flags := Flags + EWX_FORCE;
    If IsWinNT Then EnableShutDown;
    ExitWindowsEx(Flags, 0)
end;

procedure RebootNT(Force:Boolean);
var
   Flags  : Longint;
begin
    Flags := EWX_REBOOT;
    If Force Then Flags := Flags + EWX_FORCE;
    If IsWinNT Then EnableShutDown;
    ExitWindowsEx(Flags, 0)
end;

procedure LogOffNT(Force:Boolean);
var
   Flags  : Longint;
begin
    Flags := EWX_LOGOFF;
    If Force Then Flags := Flags + EWX_FORCE;
    If IsWinNT Then EnableShutDown;
    ExitWindowsEx(Flags, 0)
end;


La franja horaria es GMT +2. Ahora son las 22:30:45.

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