Solved

To shut down the machine

Posted on 2003-11-11
11
443 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
  • 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 20 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
conditional code and condition difference 9 83
ffmpeg - "rtsp://...... Operation not permitted" 4 81
Window placement 17 83
Way to decrease size of apk file 9 71
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.

831 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