Subject: Re: reboot, anyone?
From: [email-masked] (Sarir Khamsi)

18 Apr 1998 07:40:49 -0700
Message-ID: <13623.57844.546000.410278.cygnus.gnu-win32@KHAMSI>
References: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
To: Arlindo da Silva <[email-masked]>
Cc: [email-masked]

>>>>> "Arlindo" == Arlindo da Silva <[email-masked]> writes:

> Hi, I'm looking for a command line, no questions asked, "reboot"
> utility for > NT.  I'd like to be able to reboot my NT box remotely
> from a telnet shell.
   
> It is important that it skips the dialog box as I won't be there to
> click the "OK" button.  Can this be done?

Try this:

----------------------------------------------------------------------------

////////////////////////////////////////////////////////////////////////////
// Loggoff.cpp: Log off user via API.
//
// S. Khamsi
// 21Mar1998
//
// $Id: Logoff.cpp,v 1.1 1998/04/17 23:12:18 khamsi Exp $
////////////////////////////////////////////////////////////////////////////

#include <iostream>
#include <windows.h>

int main (int argc, char *argv[])
{
   if (argc == 1)
   {
      std::cout << "\nusage: " << argv[0] << " 0|1|2|3\nwhere 0 = logoff"
                << ", 1 = power off, 2 = reboot, 3 = shutdown\n" << std::endl;
      exit (1);
   }

   HANDLE hToken; 
   TOKEN_PRIVILEGES tkp; 
   DWORD LastError;
 
   // Get a token for this process. 
   if (!::OpenProcessToken (GetCurrentProcess(), 
                            TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) 
      std::cout << "OpenProcessToken() error" << std::endl;
 
   // Get the LUID for the shutdown privilege. 
   ::LookupPrivilegeValue (NULL, SE_SHUTDOWN_NAME, 
                           &tkp.Privileges[0].Luid); 
 
   tkp.PrivilegeCount = 1;  // one privilege to set    
   tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 

   // Get the shutdown privilege for this process. 
   ::AdjustTokenPrivileges (hToken, FALSE, &tkp, 0, 
                            (PTOKEN_PRIVILEGES)NULL, 0); 
 
   // Cannot test the return value of AdjustTokenPrivileges. 
   if (GetLastError() != ERROR_SUCCESS) 
      std::cout << "Error: " << LastError << " with call to "
                << "::AdjustTokenPrivileges()" << std::endl;

   UINT Flag = ::atoi (argv[1]);
   switch (Flag)
   {
   case 0:
      ::ExitWindowsEx (EWX_LOGOFF, 0);
      break;
   case 1:
      ::ExitWindowsEx (EWX_POWEROFF, 0);
      break;
   case 2:
      ::ExitWindowsEx (EWX_REBOOT | EWX_FORCE, 0);
      break;
   case 3:
      ::ExitWindowsEx (EWX_SHUTDOWN | EWX_FORCE, 0);
      break;
   default:
      std::cout << "argument must be with in range 0 - 3" << std::endl;
      exit (1);
      break;
   }

   return 0;
}

----------------------------------------------------------------------------

Let me know if you need the binary.

Sarir

-- 
Sarir "Riri" Khamsi                            Kwajalein, Marshall Islands
email: [email-masked]                       w: 805-355-1534
Time Zone: GMT +12 hours                                   f: 805-355-3833

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".