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. shut down the pc when finish...

shut down the pc when finish...

Scheduled Pinned Locked Moved C / C++ / MFC
question
12 Posts 5 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.
  • N Naveen

    Ing.Raiz82 wrote:

    "ExitWindowsEx(EWX_SHUTDOWN ,EWX_FORCE);"

    the parameter are incorrect. Use a below ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, SHTDN_REASON_MAJOR_OTHER );

    nave

    I Offline
    I Offline
    Ing Raiz82
    wrote on last edited by
    #3

    thanks.... but don't work... i don't understand.... i create a simple button and.. void CSmartAdvertiseDlg::OnBnClickedButton1() { ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, SHTDN_REASON_MAJOR_OTHER ); } but don't work.....ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh thanks giulio

    H 1 Reply Last reply
    0
    • I Ing Raiz82

      Hi, another question: i want to shut down the pc... i tried with "ExitWindowsEx(EWX_SHUTDOWN ,EWX_FORCE);" EWX_POWEROFF but don't work.... have you got an idea? regards :)giulio

      D Offline
      D Offline
      Don Box
      wrote on last edited by
      #4

      U can't directly use this API. To use the API, u'r process should have sufficient privileges. The Privilege required is SE_SHUTDOWN_NAME. Use

      OpenProcessToken()

      and

      AdjustTokenPrivileges()

      to get the right privilege.

      Come online at:- jubinc@skype

      I 1 Reply Last reply
      0
      • D Don Box

        U can't directly use this API. To use the API, u'r process should have sufficient privileges. The Privilege required is SE_SHUTDOWN_NAME. Use

        OpenProcessToken()

        and

        AdjustTokenPrivileges()

        to get the right privilege.

        Come online at:- jubinc@skype

        I Offline
        I Offline
        Ing Raiz82
        wrote on last edited by
        #5

        thanks a lot... but i'm a beginner... can you see me an example? sorry... and thanks too...

        H 1 Reply Last reply
        0
        • I Ing Raiz82

          thanks.... but don't work... i don't understand.... i create a simple button and.. void CSmartAdvertiseDlg::OnBnClickedButton1() { ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, SHTDN_REASON_MAJOR_OTHER ); } but don't work.....ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh thanks giulio

          H Offline
          H Offline
          Hamid Taebi
          wrote on last edited by
          #6

          Whats return value of ExitWindowsEx


          WhiteSky


          1 Reply Last reply
          0
          • I Ing Raiz82

            Hi, another question: i want to shut down the pc... i tried with "ExitWindowsEx(EWX_SHUTDOWN ,EWX_FORCE);" EWX_POWEROFF but don't work.... have you got an idea? regards :)giulio

            H Offline
            H Offline
            Hamid Taebi
            wrote on last edited by
            #7

            See Abort system shutdown[^] if helpfuls


            WhiteSky


            I 1 Reply Last reply
            0
            • I Ing Raiz82

              thanks a lot... but i'm a beginner... can you see me an example? sorry... and thanks too...

              H Offline
              H Offline
              Hamid Taebi
              wrote on last edited by
              #8

              See here[^] how to use this function ;)


              WhiteSky


              1 Reply Last reply
              0
              • H Hamid Taebi

                See Abort system shutdown[^] if helpfuls


                WhiteSky


                I Offline
                I Offline
                Ing Raiz82
                wrote on last edited by
                #9

                thank you so much.. bye... Giulio

                H 1 Reply Last reply
                0
                • I Ing Raiz82

                  thank you so much.. bye... Giulio

                  H Offline
                  H Offline
                  Hamid Taebi
                  wrote on last edited by
                  #10

                  You're welcome;)


                  WhiteSky


                  1 Reply Last reply
                  0
                  • I Ing Raiz82

                    Hi, another question: i want to shut down the pc... i tried with "ExitWindowsEx(EWX_SHUTDOWN ,EWX_FORCE);" EWX_POWEROFF but don't work.... have you got an idea? regards :)giulio

                    I Offline
                    I Offline
                    Ing Raiz82
                    wrote on last edited by
                    #11

                    ok.... This is the code... it work....:) //giulio shutdown pc HANDLE hToken; TOKEN_PRIVILEGES tkp; if (OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) { LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid); tkp.PrivilegeCount = 1; tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; if(AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0)) { ExitWindowsEx(EWX_SHUTDOWN|EWX_POWEROFF|EWX_FORCE,0); } } :):):):):):):):) Bye Giulio

                    1 Reply Last reply
                    0
                    • I Ing Raiz82

                      Hi, another question: i want to shut down the pc... i tried with "ExitWindowsEx(EWX_SHUTDOWN ,EWX_FORCE);" EWX_POWEROFF but don't work.... have you got an idea? regards :)giulio

                      S Offline
                      S Offline
                      Sumesh V V
                      wrote on last edited by
                      #12

                      ExitWindowsEx Windows NT/2000/XP: To shut down or restart the system, the calling process must use the AdjustTokenPrivileges function to enable the SE_SHUTDOWN_NAME privilege. For more information about security privileges, see Privileges. Windows 95/98/Me: ExitWindowEx does not work from a console application. HANDLE hToken; // handle to process token TOKEN_PRIVILEGES tkp; // pointer to token structure if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) { return (FALSE); } LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid); tkp.PrivilegeCount = 1; // one privilege to set tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; // Get shutdown privilege for this process. AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES) NULL, 0); Then call ExitWindowsEx function :)

                      Known is a drop, unknown is an ocean

                      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