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. system reboot

system reboot

Scheduled Pinned Locked Moved C / C++ / MFC
questionjsonhelptutorial
4 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.
  • U Offline
    U Offline
    User 38905
    wrote on last edited by
    #1

    Hi! I have written an NT Service to monitor an application execution. The NT Service detect properly when the application crashes (deadlock). In order to reboot the system I am using the API function ExitWindowsEx to reboot the system, but it doesn’t work very well. As a matter of fact, when I call this API function the system shows a blue screen and stay in this situation timelessly. The code that I am using (the shut down example from MSDN) is show below (I guess I have got the right privilege). Does anybody know how can I make the system reboot properly? Thank you very much for your attention. Sergio HANDLE hToken; TOKEN_PRIVILEGES tkp; // Get a token for this process. if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) error("OpenProcessToken"); // 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) error("AdjustTokenPrivileges"); // Shut down the system and force all applications to close. if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) error("ExitWindowsEx");

    E M R 3 Replies Last reply
    0
    • U User 38905

      Hi! I have written an NT Service to monitor an application execution. The NT Service detect properly when the application crashes (deadlock). In order to reboot the system I am using the API function ExitWindowsEx to reboot the system, but it doesn’t work very well. As a matter of fact, when I call this API function the system shows a blue screen and stay in this situation timelessly. The code that I am using (the shut down example from MSDN) is show below (I guess I have got the right privilege). Does anybody know how can I make the system reboot properly? Thank you very much for your attention. Sergio HANDLE hToken; TOKEN_PRIVILEGES tkp; // Get a token for this process. if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) error("OpenProcessToken"); // 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) error("AdjustTokenPrivileges"); // Shut down the system and force all applications to close. if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) error("ExitWindowsEx");

      E Offline
      E Offline
      Ernest Laurentin
      wrote on last edited by
      #2

      BTW, Welcome Sergio! I saw your name as a new member! :-) For your problem, I think you didn't get the right privilege, try adding a Messagebox or something in your app to verify that. I am pretty sure you didn't obtain the privilege. Good luck! One good thing about getting older, you don't lose the ages you've been!

      1 Reply Last reply
      0
      • U User 38905

        Hi! I have written an NT Service to monitor an application execution. The NT Service detect properly when the application crashes (deadlock). In order to reboot the system I am using the API function ExitWindowsEx to reboot the system, but it doesn’t work very well. As a matter of fact, when I call this API function the system shows a blue screen and stay in this situation timelessly. The code that I am using (the shut down example from MSDN) is show below (I guess I have got the right privilege). Does anybody know how can I make the system reboot properly? Thank you very much for your attention. Sergio HANDLE hToken; TOKEN_PRIVILEGES tkp; // Get a token for this process. if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) error("OpenProcessToken"); // 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) error("AdjustTokenPrivileges"); // Shut down the system and force all applications to close. if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) error("ExitWindowsEx");

        M Offline
        M Offline
        Mauricio Ritter
        wrote on last edited by
        #3

        Hi Sergio ! Welcome to CP ! I don´t know if this would help but try to change the ExitWindowsEx stuff for this: InitiateSystemShutdown(NULL, NULL, 0, TRUE, FALSE); Mauricio Ritter - Brazil Sonorking now: 100.13560 Trank :beer: The alcohol is one of the greatest enemys of man, but a man who flee from his enemys is a coward. :beer:

        1 Reply Last reply
        0
        • U User 38905

          Hi! I have written an NT Service to monitor an application execution. The NT Service detect properly when the application crashes (deadlock). In order to reboot the system I am using the API function ExitWindowsEx to reboot the system, but it doesn’t work very well. As a matter of fact, when I call this API function the system shows a blue screen and stay in this situation timelessly. The code that I am using (the shut down example from MSDN) is show below (I guess I have got the right privilege). Does anybody know how can I make the system reboot properly? Thank you very much for your attention. Sergio HANDLE hToken; TOKEN_PRIVILEGES tkp; // Get a token for this process. if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) error("OpenProcessToken"); // 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) error("AdjustTokenPrivileges"); // Shut down the system and force all applications to close. if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) error("ExitWindowsEx");

          R Offline
          R Offline
          Richard Ellis
          wrote on last edited by
          #4

          G'Day Sergio, A while ago I wrote a NT Service that would reboot my pc. As suggested by Mauricio I used InitiateSystemShutdown. If you want the pc to reboot rather than shutdown then the last parameter should be TRUE rather than FALSE in Mauricio's example. With respect to priveleges - SE_SHUTDOWN_NAME is the only one that I have used. Good Luck Richard.

          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