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#
  4. Restart computer from windows dialog

Restart computer from windows dialog

Scheduled Pinned Locked Moved C#
c++helpquestion
8 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.
  • K Offline
    K Offline
    kyledunn
    wrote on last edited by
    #1

    Can anyone help me with C++ code that will allow me to offer the user the choice to restart the computer from a windows dialog box? Kyle

    N 1 Reply Last reply
    0
    • K kyledunn

      Can anyone help me with C++ code that will allow me to offer the user the choice to restart the computer from a windows dialog box? Kyle

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #2

      ExitWindowsEx(EWX_REBOOT,SHTDN_REASON_MAJOR_APPLICATION); Nish


      Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

      L 1 Reply Last reply
      0
      • N Nish Nishant

        ExitWindowsEx(EWX_REBOOT,SHTDN_REASON_MAJOR_APPLICATION); Nish


        Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        where is ExitWindowsEx in the .NET Framework? I can't find it anywhere.

        J 1 Reply Last reply
        0
        • L Lost User

          where is ExitWindowsEx in the .NET Framework? I can't find it anywhere.

          J Offline
          J Offline
          James T Johnson
          wrote on last edited by
          #4

          It isn't, you need to use P/Invoke; kyle posted to the wrong forum ;P [DllImport("user32.dll")] public external static bool ExitWindowsEx(uint uFlags, int dwReason); Search through the Vc7\PlatformSDK\Include directory to get the constants needed for the paramters. James Simplicity Rules!

          K 1 Reply Last reply
          0
          • J James T Johnson

            It isn't, you need to use P/Invoke; kyle posted to the wrong forum ;P [DllImport("user32.dll")] public external static bool ExitWindowsEx(uint uFlags, int dwReason); Search through the Vc7\PlatformSDK\Include directory to get the constants needed for the paramters. James Simplicity Rules!

            K Offline
            K Offline
            kyledunn
            wrote on last edited by
            #5

            I did think I was in the C++ forum when I posted. Please accept my apology. Your answer was excellent and it made me question, is there a way to restart the computer using C# managed code? Kyle

            J N 3 Replies Last reply
            0
            • K kyledunn

              I did think I was in the C++ forum when I posted. Please accept my apology. Your answer was excellent and it made me question, is there a way to restart the computer using C# managed code? Kyle

              J Offline
              J Offline
              James T Johnson
              wrote on last edited by
              #6

              kyledunn wrote: Please accept my apology. No problems :) kyledunn wrote: is there a way to restart the computer using C# managed code? AFAIK there isn't; I haven't run across one anyway. James Simplicity Rules!

              1 Reply Last reply
              0
              • K kyledunn

                I did think I was in the C++ forum when I posted. Please accept my apology. Your answer was excellent and it made me question, is there a way to restart the computer using C# managed code? Kyle

                N Offline
                N Offline
                Neil Van Note
                wrote on last edited by
                #7

                It is very doable from WMI API wrapped in the .NET System.Managment namespace. You can reboot/shutdown the local or any other machine on the domain. Depending on the privileges you or your admin have set, your mileage will vary. Regards

                1 Reply Last reply
                0
                • K kyledunn

                  I did think I was in the C++ forum when I posted. Please accept my apology. Your answer was excellent and it made me question, is there a way to restart the computer using C# managed code? Kyle

                  N Offline
                  N Offline
                  Neil Van Note
                  wrote on last edited by
                  #8

                  using System.Management;

                  .
                  .
                  .
                  ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem WHERE Primary = TRUE");
                  ManagementBaseObject inParams;
                  ManagementBaseObject outParams;
                  bool temp;

                  foreach (ManagementObject os in searcher.Get())
                  {
                  temp = os.Scope.Options.EnablePrivileges;
                  os.Scope.Options.EnablePrivileges = true;
                  inParams = os.GetMethodParameters("Reboot");
                  outParams = os.InvokeMethod("Reboot", inParams, null);
                  os.Scope.Options.EnablePrivileges = temp;
                  }

                  You can also specify Shutdown for the method...

                  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