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#
  4. Reboot a Server with C#

Reboot a Server with C#

Scheduled Pinned Locked Moved C#
csharptutorialsysadminhelpquestion
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.
  • A Offline
    A Offline
    athomas4219
    wrote on last edited by
    #1

    I am looking to remotely reboot a server through C#. I have a VBScript example from Microsoft, but I can't seem to figure out how to move it to .NET. I'm also unable to figure out how to use the WMI (System.Management) classes to reboot. Can anyone help me, either with source code examples or other websites to check? Thanks!

    N 1 Reply Last reply
    0
    • A athomas4219

      I am looking to remotely reboot a server through C#. I have a VBScript example from Microsoft, but I can't seem to figure out how to move it to .NET. I'm also unable to figure out how to use the WMI (System.Management) classes to reboot. Can anyone help me, either with source code examples or other websites to check? Thanks!

      N Offline
      N Offline
      NormDroid
      wrote on last edited by
      #2

      Oh know its a case of DLLimport ExitWindows is the function your after, but you'll have to DLLimport to use it.

      J A 2 Replies Last reply
      0
      • N NormDroid

        Oh know its a case of DLLimport ExitWindows is the function your after, but you'll have to DLLimport to use it.

        J Offline
        J Offline
        J Liss
        wrote on last edited by
        #3

        If the server is remote, then you can also use wmi to shut it down. In your msdn: ms-help://MS.VSCC/MS.MSDNVS/wmisdk/u_ctrl_2ndx.htm

        1 Reply Last reply
        0
        • N NormDroid

          Oh know its a case of DLLimport ExitWindows is the function your after, but you'll have to DLLimport to use it.

          A Offline
          A Offline
          athomas4219
          wrote on last edited by
          #4

          I want to do it to a remote computer, so I suspect it's a WMI thing. Anyone have any idea how to do this through WMI?

          T 1 Reply Last reply
          0
          • A athomas4219

            I want to do it to a remote computer, so I suspect it's a WMI thing. Anyone have any idea how to do this through WMI?

            T Offline
            T Offline
            thematt
            wrote on last edited by
            #5

            Here is an example: string server = @"\\" + txtServer.Text; ManagementScope ms = new ManagementScope(server + @"\root\cimv2"); ObjectQuery oq = new ObjectQuery("select * from win32_OperatingSystem"); ManagementObjectSearcher mos = new ManagementObjectSearcher(ms, oq); ManagementObjectCollection moc = mos.Get(); foreach(ManagementObject mo in moc) { string[] ss = {""}; mo.InvokeMethod("Reboot", ss); MessageBox.Show("The reboot command has been sent."); } The only difference between local and remote reboots is the ManagementScope and the optional ConnectionOptions. Matt is a network administrator for an auditing company in the midwest. He is shamelessly looking for Windows programming side jobs.

            A 1 Reply Last reply
            0
            • T thematt

              Here is an example: string server = @"\\" + txtServer.Text; ManagementScope ms = new ManagementScope(server + @"\root\cimv2"); ObjectQuery oq = new ObjectQuery("select * from win32_OperatingSystem"); ManagementObjectSearcher mos = new ManagementObjectSearcher(ms, oq); ManagementObjectCollection moc = mos.Get(); foreach(ManagementObject mo in moc) { string[] ss = {""}; mo.InvokeMethod("Reboot", ss); MessageBox.Show("The reboot command has been sent."); } The only difference between local and remote reboots is the ManagementScope and the optional ConnectionOptions. Matt is a network administrator for an auditing company in the midwest. He is shamelessly looking for Windows programming side jobs.

              A Offline
              A Offline
              athomas4219
              wrote on last edited by
              #6

              That last one worked like a champ. Thanks!

              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