ExitWindowsEx Problem
-
Hi, I have a program and somewhere in the program, I need to shutdown the computer. The following code works fine on my machine (W2K) however, it does not work on some other machines ( on Win98 and NT ). It does not shutdown the computer, instead it logs off or reboots the computer. Please help. Is there any way to shutdown the computer without any problems (not only shutdown but also power off!)? Best Regards ----------------------- int CTaskStep::ExecuteShutDown ( CTaskObject *pTask , bool bReboot) { HANDLE hProcess = GetCurrentProcess(); // Is pseudohandle, no close needed HANDLE hToken = NULL; OpenProcessToken(hProcess,TOKEN_ADJUST_PRIVILEGES,&hToken); if ( hToken ) { TOKEN_PRIVILEGES priv_struct; LUID_AND_ATTRIBUTES priv; LUID priv_luid; BOOL bRet; bRet = LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &priv_luid); priv.Attributes = SE_PRIVILEGE_ENABLED; priv.Luid = priv_luid; priv_struct.PrivilegeCount = 1; priv_struct.Privileges->Attributes = SE_PRIVILEGE_ENABLED; priv_struct.Privileges->Luid = priv_luid; bRet = AdjustTokenPrivileges(hToken, FALSE, &priv_struct,NULL,NULL, NULL); CloseHandle( hToken ); } // Restart and give message to restart if failed if ( bReboot ) { if(!ExitWindowsEx (EWX_REBOOT | EWX_FORCE,0) ) { CString str; str.LoadString( IDS_MBOX_FAILED_RESTART ); AfxMessageBox(str,MB_ICONERROR); m_bFailed = true; } } else { if(!ExitWindowsEx(EWX_POWEROFF | EWX_FORCE,0)) { CString str; str.LoadString( IDS_MBOX_FAILED_SHUTDOWN ); AfxMessageBox(str,MB_ICONERROR); m_bFailed = true; } } return EX_CONTINUE; } Mustafa Demirhan