ExitWindowsEx Problem!!
-
Hi, In one of my programs, I am trying to shutdown windows. The following code works well under W2k but it does not work under WinME/9x. It starts the shutdown process, it closes all windows and then hides the taskbar but then it stops. Please help. Is there any problems with the code? PS. The reboot operation works well.
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 ); } if ( bReboot ) { if(!ExitWindowsEx (EWX_REBOOT | EWX_FORCE,0) ) return MSG_FAILED; } else { if(!ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCE, 0)) return MSG_FAILED; } return EX_CONTINUE; }
Kind regards Mustafa Demirhan