how do i call the dialog box for shutdown computer?

Posted on 2002-03-14
Medium Priority
Last Modified: 2008-03-17
I want to call for dialog box "shutdown windows".

I was using ExitwindowsEx, but didn't function.

I am using Vc++. in windows 9x, with a program of the type "win32 console Application".


"ExitwindowsEX(EWX_SHUTDOWN| EWX_FORCE,0)" didn't run correctly. it only closed all programas, but it
don't shutdown my computer(turn - off). I am using Win95, and VC++. My program is "Win32 console Application".

I try with program of the type "Win32 Application", it closed all program and show the message "wait
windows is shutDown........", but it show the message FOREVER.

what is it wrong?


    ShutdownSystem(EWX_SHUTDOWN | EWX_FORCE);


BOOL ShutdownSystem(unsigned int uFlags)
       HANDLE hToken;
       BOOL bOkShutdown;
    BOOL fResult;
       const char szShutdown[] = "SeShutdownPrivilege";

            if(OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &hToken) )

               LookupPrivilegeValue("",szShutdown, &tkp.Privileges[0].Luid);
              tkp.PrivilegeCount = 1;
           tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
           bOkShutdown = (AdjustTokenPrivileges(hToken,0,&tkp,0,(PTOKEN_PRIVILEGES)NULL,0)!=0);
    else {
    fResult =  ExitWindowsEx(uFlags,0);
       return (fResult!=0);
   return false;
Question by:alexBrasil
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
  • 3
  • 2
LVL 49

Accepted Solution

DanRollins earned 200 total points
ID: 6866339
Some computers cannot be turned off by software.  Can you turn off you computer by using the "Shut down..." command on the [Start] button?  If not, then your computer is one of those.

Do you get any different behavior if you use different flags:


-- Dan
LVL 49

Expert Comment

ID: 6866368
Also you need to send NULL (not "") in the LookupPrivilegeValue() API call.  Here is some code from MSDN:

HANDLE hToken;
BOOL fRet= OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken);
if (!fRet ) {
    // error("OpenProcessToken");
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
tkp.PrivilegeCount= 1;  
tkp.Privileges[0].Attributes= SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
if (GetLastError() != ERROR_SUCCESS)  {
    // error("AdjustTokenPrivileges");

fRet= ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0);
if ( !fRet ) {
   // error("ExitWindowsEx");

-- Dan

Author Comment

ID: 6894004
I am using Win98, then when i use "EWX_SHUTDOWN | EWX_FORCE", my computer HANG. because it's a bug of win9x.

Other thing, in a program of kind "WIn32 console application", ExitwindowsEx do not function, it just function in programs of kind "Win32 Application".


I used a program of kind "Win32 Application" with ExixwindowsEx(EWX_SHUTDOWN) ( i do not can to use EWX_FORCE).
LVL 49

Expert Comment

ID: 6895251
hi alexBrasil,
It is not kind to give a 'C' grade.  In fact it is an insult.  It is better to ask the expert for additional help so that he can make you so very happy that you give a B or an A.

Thank you.

-- Dan

Author Comment

ID: 6897096

Thank you.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses
Course of the Month14 days, 8 hours left to enroll

771 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