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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. restarting PC

restarting PC

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelptutorial
3 Posts 3 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
    boon kian
    wrote on last edited by
    #1

    Hi , I have a question here regarding how to use C to restart the PC. situation: I am using win2000 but however I would like to bootup using a win98 floppy disk to verify my systems settings. after checking I would like the PC to reboot so that it can boot from the HD into win2000. I am thinking of using autoexec.bat to help me to automate this process. So how can I write a simple c program to reboot my pc automatically so that i can activate the program through autoexec.bat ?? Please advise! Thank you bk

    S 1 Reply Last reply
    0
    • B boon kian

      Hi , I have a question here regarding how to use C to restart the PC. situation: I am using win2000 but however I would like to bootup using a win98 floppy disk to verify my systems settings. after checking I would like the PC to reboot so that it can boot from the HD into win2000. I am thinking of using autoexec.bat to help me to automate this process. So how can I write a simple c program to reboot my pc automatically so that i can activate the program through autoexec.bat ?? Please advise! Thank you bk

      S Offline
      S Offline
      Serge Krynine
      wrote on last edited by
      #2

      Use the ExitWindowsEx() function with the EWX_REBOOT flag. Serge

      R 1 Reply Last reply
      0
      • S Serge Krynine

        Use the ExitWindowsEx() function with the EWX_REBOOT flag. Serge

        R Offline
        R Offline
        rohit dhamija 0
        wrote on last edited by
        #3

        You need to get priveldges first.Use rebootmysystem() to get priveledges. Best of luck.;) /////////////////////////// void rebootmysystem() if(!ExitWindowsEx(EWX_REBOOT| EWX_FORCE ,0)) MessageBox("Couldn't reboot! Please do it manually.", "Installation Complete", MB_OK); //////////////////////////// //to get priveledges void rebootmysystem() { HANDLE hToken; TOKEN_PRIVILEGES tkp; // Get a token for this process. if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) AfxMessageBox("Cannot Proceed!. Please restart manually"); // Get the LUID for the shutdown privilege. LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid); tkp.PrivilegeCount = 1; // one privilege to set tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; // Get the shutdown privilege for this process. AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0); // Cannot test the return value of AdjustTokenPrivileges. if (GetLastError() != ERROR_SUCCESS) AfxMessageBox("Cannot Proceed!. Please restart manually"); // Shut down the system and force all applications to close. }

        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