Solved

how do i call the dialog box for shutdown computer?

Posted on 2002-03-14
5
387 Views
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".


overview:


"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?

Example:

call:
    ShutdownSystem(EWX_SHUTDOWN | EWX_FORCE);

Program:

BOOL ShutdownSystem(unsigned int uFlags)
{
       HANDLE hToken;
       TOKEN_PRIVILEGES tkp;
       BOOL bOkShutdown;
    BOOL fResult;
       OSVERSIONINFO osv;
       const char szShutdown[] = "SeShutdownPrivilege";
       osv.dwOSVersionInfoSize=sizeof(osv);
       GetVersionEx(&osv);
       

       if(osv.dwPlatformId==VER_PLATFORM_WIN32_NT)
    {
            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 {
         bOkShutdown=true;
       }
   if(bOkShutdown)
   {
    fResult =  ExitWindowsEx(uFlags,0);
       return (fResult!=0);
   }
   return false;
}
0
Comment
Question by:alexBrasil
[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
  • 3
  • 2
5 Comments
 
LVL 49

Accepted Solution

by:
DanRollins earned 100 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:

      EWX_REBOOT | EWX_FORCE
or
      EWX_POWEROFF | EWX_FORCEIFHUNG

-- Dan
0
 
LVL 49

Expert Comment

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

HANDLE hToken;
TOKEN_PRIVILEGES tkp;
 
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
0
 

Author Comment

by:alexBrasil
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".

Solucion:

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

Expert Comment

by:DanRollins
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
0
 

Author Comment

by:alexBrasil
ID: 6897096
Sorry.


Thank you.
0

Featured Post

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.

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…
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 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.

707 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