Board index » delphi » Reboot WinNT/2000

Reboot WinNT/2000

Hello,
Surfing thru Internet I have found some advices how I can restart Windows
95/98.
F.e.
    ExitWindowsEx(EWX_FORCE, 0);
    ExitWindowsEx(EWX_POWEROFF, 0);
    ExitWindowsEx(EWX_REBOOT, 0);

In the case when I want to restart Windows NT or 2000 it does not work
properly.
The only effect I got was the log off of the user.

I have the task to log off the user and reboot computer (or completely
shutdown the system). It there any way to do that?

I have both: Delphi 5.0 and 6.0.

Thanks in advance for your help.
Przemyslaw Czaplinski

 

Re:Reboot WinNT/2000


I don't know how to do this but your problem is that the logged on user does
not have rights to restart windows. You need to 'fake' a user with this
privilage and then execute the restart command.

Quote
"Przemyslaw Czaplinski" <ge...@thenut.eti.pg.gda.pl> wrote in message

news:9le8hh$rn4$1@news.tpi.pl...
Quote
> Hello,
> Surfing thru Internet I have found some advices how I can restart Windows
> 95/98.
> F.e.
>     ExitWindowsEx(EWX_FORCE, 0);
>     ExitWindowsEx(EWX_POWEROFF, 0);
>     ExitWindowsEx(EWX_REBOOT, 0);

> In the case when I want to restart Windows NT or 2000 it does not work
> properly.
> The only effect I got was the log off of the user.

> I have the task to log off the user and reboot computer (or completely
> shutdown the system). It there any way to do that?

> I have both: Delphi 5.0 and 6.0.

> Thanks in advance for your help.
> Przemyslaw Czaplinski

Re:Reboot WinNT/2000


Hi Przemyslaw,

Quote
>I have the task to log off the user and reboot computer (or completely
>shutdown the system). It there any way to do that?

Try this code:
// === [code: Exiting Windows] ===
  procedure QuitWindows(uFlags: UINT; forced: boolean);
  // uFlages can be:
  //    EWX_LOGOFF
  //    EWX_REBOOT
  //    EWX_SHUTDOWN
  var
    hProcess: THandle;
    hToken: THandle;
    tpAct, tpPrev: TTokenPrivileges;
    wDummy: DWORD;
  begin
    hProcess:= GetCurrentProcess;
    OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,
  hToken);
    LookupPrivilegeValue(nil, 'SeShutdownPrivilege',
  tpAct.Privileges[0].Luid);
    tpPrev:= tpAct;
    tpAct.PrivilegeCount:= 1;
    tpAct.Privileges[0].Attributes:= 2;
    AdjustTokenPrivileges(hToken, false, tpAct, SizeOf(tpPrev), tpPrev,
  wDummy);
    if forced then
      uFLags:= uFlags or EWX_FORCE;
    ExitWindowsEx(uFlags, 0);
  end;
// === [end of code] ===

Cheers,
   Udo
--
Homepage: http://www.nesshoever.de            No mails please. Reply here.

Delphi env.:                         Global Polio Awareness Campaign 2001+
W2K.sp2, D6Pro & D4Pro.sp3               More info -> http://www.2-mad.com

Re:Reboot WinNT/2000


Thank you dudes,
Now it is working great. :-)

Best regards,
Przemyslaw Czaplinski

Quote
"Udo Nesshoever" <newsgroup.re...@gmx.net> wrote in message

news:9lg6r3.100.2@com.nesshoever.net...
Quote
> Hi Przemyslaw,

> >I have the task to log off the user and reboot computer (or completely
> >shutdown the system). It there any way to do that?

> Try this code:
> // === [code: Exiting Windows] ===
>   procedure QuitWindows(uFlags: UINT; forced: boolean);
>   // uFlages can be:
>   //    EWX_LOGOFF
>   //    EWX_REBOOT
>   //    EWX_SHUTDOWN
>   var
>     hProcess: THandle;
>     hToken: THandle;
>     tpAct, tpPrev: TTokenPrivileges;
>     wDummy: DWORD;
>   begin
>     hProcess:= GetCurrentProcess;
>     OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,
>   hToken);
>     LookupPrivilegeValue(nil, 'SeShutdownPrivilege',
>   tpAct.Privileges[0].Luid);
>     tpPrev:= tpAct;
>     tpAct.PrivilegeCount:= 1;
>     tpAct.Privileges[0].Attributes:= 2;
>     AdjustTokenPrivileges(hToken, false, tpAct, SizeOf(tpPrev), tpPrev,
>   wDummy);
>     if forced then
>       uFLags:= uFlags or EWX_FORCE;
>     ExitWindowsEx(uFlags, 0);
>   end;
> // === [end of code] ===

> Cheers,
>    Udo
> --
> Homepage: http://www.nesshoever.de            No mails please. Reply here.

> Delphi env.:                         Global Polio Awareness Campaign 2001+
> W2K.sp2, D6Pro & D4Pro.sp3               More info -> http://www.2-mad.com

Other Threads