This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: reboot, anyone?


>>>>> "Arlindo" == Arlindo da Silva <arlindo@niteroi.gsfc.nasa.gov> 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: khamsi@kmrmail.kmr.ll.mit.edu                       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
"gnu-win32-request@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]