Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. ExitWindowsEx Problem

ExitWindowsEx Problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mustafa Demirhan
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups