Solved

Shutting down Windows XP

Posted on 2004-09-05
9
194 Views
Last Modified: 2010-04-01
How do I programmatically shut down Windows Xp properly?
0
Comment
Question by:bradsoblesky
9 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 168 total points
ID: 11984562
       HANDLE hToken;
        TOKEN_PRIVILEGES tkp;
 
        // Get a token for this process.
        if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
        {
            // Get the LUID for the shutdown privilege.
            LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
 
            tkp.PrivilegeCount = 1;  // one privilege to set    
            tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
 
            // Get the shutdown privilege for this process.
            AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
 
 
            ExitWindowsEx(EWX_POWEROFF | EWX_FORCE, 0);
        }
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 166 total points
ID: 11985077
I'd prefer

InitiateSystemShutdown ( NULL, NULL, 5, TRUE, FALSE);

over 'ExitWindowsEx()', but that's just my personal preference
0
 

Author Comment

by:bradsoblesky
ID: 11995449
seem like neither of these suggestions are working.
0
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.

 
LVL 6

Assisted Solution

by:Fahdmurtaza
Fahdmurtaza earned 166 total points
ID: 11995838
Well I think what you need is the free code at....

http://www.codeproject.com/useritems/standstillpcasp.asp

All you have to do is that just make  free account over there. I have been a member ovr there for last three years and I learned alot..

Regards
Fahd Murtaza
0
 
LVL 6

Expert Comment

by:Fahdmurtaza
ID: 12305192
I think you are right Tincho. He hasn't responded and now after this comment being added he should respond.
Regards,
Fahd Murtaza
0
 
LVL 6

Expert Comment

by:Fahdmurtaza
ID: 12562563
Ok man just do it as it may be useful for someon else at ee.
Regards,
Fahd Murtaza
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

832 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