Board index » delphi » Shutdown WinNT/2000

Shutdown 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:Shutdown WinNT/2000


To shutdown Windows on NT/2000 use:

Use:

var
  TokenHandle: THandle;
  NewState, PreviousState: TTokenPrivileges;
  ReturnLength: DWORD;
begin
  if not OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or
TOKEN_QUERY, TokenHandle) then
    RaiseLastWin32Error;
  try
    NewState.PrivilegeCount := 1;
    if not LookupPrivilegeValue(nil, 'SeShutdownPrivilege',
NewState.Privileges[0].LUID) then
      RaiseLastWin32Error;
    NewState.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
    ReturnLength := 0;
    if not AdjustTokenPrivileges(TokenHandle, False, NewState,
SizeOf(NewState), PreviousState, ReturnLength) then
      RaiseLastWin32Error;
  finally
    CloseHandle(TokenHandle);
  end;
  if not ExitWindowsEx(EWX_FORCE or EWX_SHUTDOWN, 0) then
    RaiseLastWin32Error;
end;

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

news:9le7ut$o85$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:Shutdown WinNT/2000


Hello,

I have tried your function under Windows 2000 with Delphi 6.0. It works
great!
Thank you :-)

Przemyslaw Czaplinski

Quote
"M.H. Avegaart" <avega...@NOSPAMmccomm.nl> wrote in message

news:9lfs57$10cg$1@scavenger.euro.net...
Quote
> To shutdown Windows on NT/2000 use:

> Use:

> var
>   TokenHandle: THandle;
>   NewState, PreviousState: TTokenPrivileges;
>   ReturnLength: DWORD;
> begin
>   if not OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or
> TOKEN_QUERY, TokenHandle) then
>     RaiseLastWin32Error;
>   try
>     NewState.PrivilegeCount := 1;
>     if not LookupPrivilegeValue(nil, 'SeShutdownPrivilege',
> NewState.Privileges[0].LUID) then
>       RaiseLastWin32Error;
>     NewState.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
>     ReturnLength := 0;
>     if not AdjustTokenPrivileges(TokenHandle, False, NewState,
> SizeOf(NewState), PreviousState, ReturnLength) then
>       RaiseLastWin32Error;
>   finally
>     CloseHandle(TokenHandle);
>   end;
>   if not ExitWindowsEx(EWX_FORCE or EWX_SHUTDOWN, 0) then
>     RaiseLastWin32Error;
> end;

> "Przemyslaw Czaplinski" <ge...@thenut.eti.pg.gda.pl> wrote in message
> news:9le7ut$o85$1@news.tpi.pl...
> > 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

Other Threads