Question About The EWX_REBOOT

This is a discussion on Question About The EWX_REBOOT within the Windows Programming forums, part of the Platform Specific Boards category; That made my pc log off.. is there a way to make it Shut Down or Reboot or something?...

  1. #16
    Registered User LogicError's Avatar
    Join Date
    Aug 2003
    Location
    г. Магнитогорск
    Posts
    76
    That made my pc log off.. is there a way to make it Shut Down or Reboot or something?

  2. #17
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    The code is actually rather trivial. Unfortunately, I *don't* think this guy needs it as bad as he thinks he does! Ah well.
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  3. #18
    Registered User LogicError's Avatar
    Join Date
    Aug 2003
    Location
    г. Магнитогорск
    Posts
    76
    I don't fell like testing it right now either lol.. will test it before I shut-down the PC

  4. #19
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    You need to enable the SE_SHUTDOWN_NAME privilige (assuming you are using Win NT/2000/XP).

    Code:
    BOOL SetProcessPrivilege(LPCTSTR lpPrivilege) {
    
    	/* This function enables a privilege for the current process */
    	/* lpPrivilege can be either a privilege constant eg. SE_SHUTDOWN_NAME
    	 * which is DEFINEd in the windows headers to the string 
    	 * "SeShutdownPrivilege" or the string can be used directly. */
    
    	TOKEN_PRIVILEGES tp;
    	HANDLE hToken;
    	LUID luid;
    	OSVERSIONINFO osvi;
    
    
    	/* Check that we are a Win NT system before proceeding */
    	osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    	GetVersionEx (&osvi);
    	if (osvi.dwPlatformId != VER_PLATFORM_WIN32_NT)
    	{
    		PRINTF("Error: System is not NT based");
    		return FALSE;
    	}
    
    
    	/* Get the local id of our desired privilege */
    	if ( !LookupPrivilegeValue( 
    		NULL,               // lookup privilege on local system
    		lpPrivilege,        // privilege to lookup 
    		&luid ) )           // receives LUID of privilege
    	{
    		PRINTF("LookupPrivilegeValue error: %u\n", GetLastError() ); 
    		return FALSE; 
    	}
    
    
    	/* Fill in TOKEN_PRIVILEGES structure */
    	tp.PrivilegeCount = 1;
    	tp.Privileges[0].Luid = luid;   // the luid of the privilege to enable
    	tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    
    
    	/* Get the access token for the current process */
    	if ( !OpenProcessToken(
    		GetCurrentProcess(),
    		TOKEN_ADJUST_PRIVILEGES,
    		&hToken ) )
    	{
    		PRINTF("OpenProcessToken error: %u\n", GetLastError() ); 
    		return FALSE; 
    	}
    
    
    	/* Enable the privilege */
    	if ( !AdjustTokenPrivileges(
    	       hToken,         // access token
    	       FALSE,          // don't disable all privileges
    	       &tp,            // TOKEN_PRIVILEGES struct
    	       sizeof(TOKEN_PRIVILEGES), 
    	       (PTOKEN_PRIVILEGES) NULL, 
    	       (PDWORD) NULL) )
    	{ 
    		PRINTF("AdjustTokenPrivileges error: %u\n", GetLastError() ); 
    		CloseHandle(hToken);
    		return FALSE; 
    	} 
    
    
    	/* Close the process access token */
    	CloseHandle(hToken);
    
    
    	return TRUE; //success
    }
    Code:
    SetProcessPrivilege(SE_SHUTDOWN_NAME);
    
    InitiateSystemShutdown(
    		  NULL,                            //LPTSTR lpMachineName,
    		  "This is an automated shutdown.",       //LPTSTR lpMessage,
    		  120,                                     //DWORD dwTimeout,
    		  FALSE,                                  //BOOL bForceAppsClosed,
    		  FALSE                                  //BOOL bRebootAfterShutdown,
    		  );

  5. #20
    Registered User LogicError's Avatar
    Join Date
    Aug 2003
    Location
    г. Магнитогорск
    Posts
    76
    I'm on windows ME

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21