Link to home
Start Free TrialLog in
Avatar of yateesh
yateesh

asked on

To shut down the machine

i want to shut down, log off, and restart the machine(running on windows) using the functions which i can implement inVC++

(iam able to only log off using ExitWindowsEx function)

plz help  in these pts

yateesh
Avatar of Priyesh
Priyesh

if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))
      return FALSE;
ASKER CERTIFIED SOLUTION
Avatar of jhance
jhance

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
     HANDLE                        hToken;
      TOKEN_PRIVILEGES      tkp;
      BOOL                        bOpenProcessTokenGood;
      
      bOpenProcessTokenGood = OpenProcessToken(GetCurrentProcess(), (TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY), &hToken );

      if( !bOpenProcessTokenGood )
      {      
            return;
      }
      
      //******************************************************************
      //* Get the LUID for the shutdown privilege.                       *
      //******************************************************************
      LookupPrivilegeValue( NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid );

      tkp.PrivilegeCount = 1;
      tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
      //******************************************************************
      // Set the shutdown privilege for this process.                    *
      //******************************************************************
      AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
      
      ExitWindowsEx( EWX_REBOOT, NULL );      
jrocnuck,

It seems you've been participating here on EE long enough to be aware of the rules...
which rule are you refering to?
or rules..
were you aware that using terms like "simipleminded" is not really appropriate according to the rules?
Note that I said the APPROACH is simpleminded.  I did NOT indicate that the user was.  Take it up with the moderators.
same back at ya jack...

The term simpleminded should never be used period, it is arrogant and the wrong choice of words.  If you cared anything about the real reason this site exists, you wouldn't use words like that and say the kinds of things I've seen you say in other posts.

This site is about helping people, not belittling them or their methods or approaches and not about boosting your ego by appearing to be a genius.