?
Solved

To shut down the machine

Posted on 2003-11-11
11
Medium Priority
?
449 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:yateesh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
11 Comments
 
LVL 9

Expert Comment

by:Priyesh
ID: 9728339
if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))
      return FALSE;
0
 
LVL 32

Accepted Solution

by:
jhance earned 80 total points
ID: 9730440
Note that the code fragment above is simpleminded.  It will work ONLY on Win9x/ME.  It will fail on NT4/2000/XP due to lack of proper privilege by the calling process.

Please see the Microsoft example here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/shutting_down.asp

It shows you exactly how to do this.  Indeed it's more complex than the above sample but having the SE_SHUTDOWN_NAME privilege is critical for success.
0
 
LVL 5

Expert Comment

by:jrocnuck
ID: 9734003
     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 );      
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
LVL 32

Expert Comment

by:jhance
ID: 9734544
jrocnuck,

It seems you've been participating here on EE long enough to be aware of the rules...
0
 
LVL 5

Expert Comment

by:jrocnuck
ID: 9735138
which rule are you refering to?
0
 
LVL 5

Expert Comment

by:jrocnuck
ID: 9735171
or rules..
0
 
LVL 5

Expert Comment

by:jrocnuck
ID: 9735184
were you aware that using terms like "simipleminded" is not really appropriate according to the rules?
0
 
LVL 32

Expert Comment

by:jhance
ID: 9736344
Note that I said the APPROACH is simpleminded.  I did NOT indicate that the user was.  Take it up with the moderators.
0
 
LVL 5

Expert Comment

by:jrocnuck
ID: 9739790
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.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question