Board index » delphi » System Restart in Win 2k

System Restart in Win 2k

Hi there,

Could anyone help me with rebooting win2k machines form a DC5 application?

Reading the help gets me to a api function called ExitWindowsEx. This thing
needs some security descriptors set but doesn't seems to work. The machine
just logs of the user instead of rebooting.

Thanks

 

Re:System Restart in Win 2k


*** post for FREE via your newsreader at post.newsfeeds.com ***

ExitWindowsEx(EWX_FORCE ,0) should do the trick I believe.

Bryan Ashby

Quote
"Clueless" <x...@x.com> wrote in message

news:996082914.16244.0.pluto.d4ee08b2@news.demon.nl...

Quote
> Hi there,

> Could anyone help me with rebooting win2k machines form a DC5 application?

> Reading the help gets me to a api function called ExitWindowsEx. This
thing
> needs some security descriptors set but doesn't seems to work. The machine
> just logs of the user instead of rebooting.

> Thanks

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 90,000 Newsgroups - 16 Different Servers! =-----

Re:System Restart in Win 2k


Quote
"Bryan Ashby" <bas...@iaccess.com> wrote in message

news:3b5f09b0$1@post.newsfeeds.com...
Quote
> *** post for FREE via your newsreader at post.newsfeeds.com ***

> ExitWindowsEx(EWX_FORCE ,0) should do the trick I believe.

> Bryan Ashby

Hi,

I tried that, but it just logs off the current user. Thanks anyway

Looking at Borland's FAQ I have the following code example for C++

bool WINAPI SystemRestart (DWORD mode)
{  
    BOOL ret;
    OSVERSIONINFO vi;

    vi.dwOSVersionInfoSize = sizeof(vi);
    GetVersionEx (&vi);
    if (vi.dwPlatformId == VER_PLATFORM_WIN32_NT) {
      HANDLE hToken;
      TOKEN_PRIVILEGES tp;

      ret = FALSE;
      if (OpenProcessToken (GetCurrentProcess (),             // open access privilege list.
          TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
        tp.PrivilegeCount = 1;
        LookupPrivilegeValue (NULL, SE_SHUTDOWN_NAME,       // Ask the "shutdown" LUID
                              &tp.Privileges[0].Luid);
        tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; // enable it
        AdjustTokenPrivileges (hToken, FALSE, &tp, 0, NULL, 0);
        ret = (GetLastError () == ERROR_SUCCESS);
      }
    }
    else
      ret = true;

    return (ret ? ExitWindowsEx (mode, 0) : false);

Quote
}

How do I know what SE_SHUTDOWN_NAME is?

Re:System Restart in Win 2k


1. You have to request shutdown priviledge first
2. You are forgetting the EWX_SHUTDOWN flag

Example:

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;

"Bryan Ashby" <bas...@iaccess.com> schreef in bericht
news:3b5f09b0$1@post.newsfeeds.com...

Quote
> *** post for FREE via your newsreader at post.newsfeeds.com ***

> ExitWindowsEx(EWX_FORCE ,0) should do the trick I believe.

> Bryan Ashby

> "Clueless" <x...@x.com> wrote in message
> news:996082914.16244.0.pluto.d4ee08b2@news.demon.nl...
> > Hi there,

> > Could anyone help me with rebooting win2k machines form a DC5
application?

> > Reading the help gets me to a api function called ExitWindowsEx. This
> thing
> > needs some security descriptors set but doesn't seems to work. The
machine
> > just logs of the user instead of rebooting.

> > Thanks

> -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
> -----==  Over 90,000 Newsgroups - 16 Different Servers! =-----

Re:System Restart in Win 2k


Thanks (again),
I saw your code example on comp.lang.pascal.delphi.misc. It really works
nice!

I changed your code only to check if the operation system is WIN 2K, but you
probably know that trix as well.

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

news:9jog48$2opd$1@scavenger.euro.net...
Quote
> 1. You have to request shutdown priviledge first
> 2. You are forgetting the EWX_SHUTDOWN flag

> Example:

> 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;

> "Bryan Ashby" <bas...@iaccess.com> schreef in bericht
> news:3b5f09b0$1@post.newsfeeds.com...
> > *** post for FREE via your newsreader at post.newsfeeds.com ***

> > ExitWindowsEx(EWX_FORCE ,0) should do the trick I believe.

> > Bryan Ashby

> > "Clueless" <x...@x.com> wrote in message
> > news:996082914.16244.0.pluto.d4ee08b2@news.demon.nl...
> > > Hi there,

> > > Could anyone help me with rebooting win2k machines form a DC5
> application?

> > > Reading the help gets me to a api function called ExitWindowsEx. This
> > thing
> > > needs some security descriptors set but doesn't seems to work. The
> machine
> > > just logs of the user instead of rebooting.

> > > Thanks

> > -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> > http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
> > -----==  Over 90,000 Newsgroups - 16 Different Servers! =-----

Other Threads