Solved

Shutting down Windows XP

Posted on 2004-09-05
9
199 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

828 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