Thread: Question About The EWX_REBOOT

  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,708
    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:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  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

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, 01:47 AM