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. How to start a PC/Application from Program

How to start a PC/Application from Program

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
6 Posts 4 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.
  • B Offline
    B Offline
    Billar
    wrote on last edited by
    #1

    Dear Friends, I would like to restart a PC whenever any error occurs in my application. How can I do so. Please help me as soon as possible. Thanking You in advance....... Billar

    2 D 2 Replies Last reply
    0
    • B Billar

      Dear Friends, I would like to restart a PC whenever any error occurs in my application. How can I do so. Please help me as soon as possible. Thanking You in advance....... Billar

      2 Offline
      2 Offline
      224917
      wrote on last edited by
      #2

      ExitWindowsEx()
      There is no spoon. mail

      V 1 Reply Last reply
      0
      • 2 224917

        ExitWindowsEx()
        There is no spoon. mail

        V Offline
        V Offline
        vcplusplus
        wrote on last edited by
        #3

        If you are using NT/2000/XP, you will need to set privileges.
        DWORD dwVersion = GetVersion(); if ( dwVersion < 0x80000000) { // NT/2000/XP HANDLE hToken; LUID tmpLuid; HANDLE handleProcess=GetCurrentProcess(); if (!OpenProcessToken(handleProcess,TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) return; if (!LookupPrivilegeValue(0,"SeShutdownPrivilege", &tmpLuid)) return; TOKEN_PRIVILEGES NewState; LUID_AND_ATTRIBUTES luidattr; NewState.PrivilegeCount = 1; luidattr.Luid=tmpLuid; luidattr.Attributes=SE_PRIVILEGE_ENABLED; NewState.Privileges[0]=luidattr; if (!AdjustTokenPrivileges(hToken, false, &NewState, sizeof(TOKEN_PRIVILEGES), 0, 0)) return; } ExitWindowsEx(...);

        B 1 Reply Last reply
        0
        • B Billar

          Dear Friends, I would like to restart a PC whenever any error occurs in my application. How can I do so. Please help me as soon as possible. Thanking You in advance....... Billar

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Billar wrote: I would like to restart a PC whenever any error occurs in my application. This is a very bad design in my opinion. :eek: Since there is no way you are going to develop an error-free application, I certainly would not want my PC restarting while I am in the middle of something important (e.g., typing research paper, presentation to the board). Do you concur?


          "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

          B 1 Reply Last reply
          0
          • D David Crow

            Billar wrote: I would like to restart a PC whenever any error occurs in my application. This is a very bad design in my opinion. :eek: Since there is no way you are going to develop an error-free application, I certainly would not want my PC restarting while I am in the middle of something important (e.g., typing research paper, presentation to the board). Do you concur?


            "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

            B Offline
            B Offline
            Billar
            wrote on last edited by
            #5

            Dear David, You r absolutely right. There will never be a solution by restarting the system instead of solving the particular error, when have errors. Actually my requirement was to restart the system on a certain condition. Billar

            1 Reply Last reply
            0
            • V vcplusplus

              If you are using NT/2000/XP, you will need to set privileges.
              DWORD dwVersion = GetVersion(); if ( dwVersion < 0x80000000) { // NT/2000/XP HANDLE hToken; LUID tmpLuid; HANDLE handleProcess=GetCurrentProcess(); if (!OpenProcessToken(handleProcess,TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) return; if (!LookupPrivilegeValue(0,"SeShutdownPrivilege", &tmpLuid)) return; TOKEN_PRIVILEGES NewState; LUID_AND_ATTRIBUTES luidattr; NewState.PrivilegeCount = 1; luidattr.Luid=tmpLuid; luidattr.Attributes=SE_PRIVILEGE_ENABLED; NewState.Privileges[0]=luidattr; if (!AdjustTokenPrivileges(hToken, false, &NewState, sizeof(TOKEN_PRIVILEGES), 0, 0)) return; } ExitWindowsEx(...);

              B Offline
              B Offline
              Billar
              wrote on last edited by
              #6

              Thanks u very much for your important advice..... Billar

              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