Reboot a Remote Computer with VB.NET

We have a training room that needs machines rebooted frequently. I attempted to write a VB.net Script to do this but am stuck.  Basically I have a form with a button that can reboot all the machines, but I want to input a text box that I can lable machine name, type the node name of the computer in there, and then hit a button that will reboot that one node name. I have nothing so far.

 Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        If Trim(TextBox1.Text) = "" Then
            MsgBox("Please enter Client Node Name!!!", MsgBoxStyle.Information, "node name???")
            TextBox1.Focus()
            Exit Sub
        End If
        If (TextBox1.Text) = "" Then



        End If
    End Sub
LVL 4
solomonacquahAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
You can use the Shutdown command from the command line.

Bob
solomonacquahAuthor Commented:
I know that but I already created this cool looking form and my life wouldn't be complete unless I learned something about VB.NET
Bob LearnedCommented:
I certainly wouldn't want to deprive you of any opportunity to learn something new.

Here is an untested WMI class:

' Add a reference to System.Management.dll to the project.

Imports System.Management

Public Enum PlatformType
  Unknown
  WorkStation
  DomainController
  Server
End Enum 'PlatformType

Public Enum SystemType
  Unknown
  Other
  MACROS
  ATTUNIX
  DGUX
  DECNT
  DigitalUnix
  OpenVMS
  HPUX
  AIX
  MVS
  OS400
  OS_2
  JavaVM
  MSDOS
  WIN3x
  WIN95
  WIN98
  WINNT
  WINCE
  NCR3000
  NetWare
  OSF
  DC_OS
  ReliantUNIX
  SCO_UnixWare
  SCO_OpenServer
  Sequent
  IRIX
  Solaris
  SunOS
  U6000
  ASERIES
  TandemNSK
  TandemNT
  BS2000
  LINUX
  Lynx
  XENIX
  VM_ESA
  Interactive_UNIX
  BSDUNIX
  FreeBSD
  NetBSD
  GNU_Hurd
  OS9
  MACH_Kernel
  Inferno
  QNX
  EPOC
  IxWorks
  VxWorks
  MiNT
  BeOS
  HP_MPE
  NextStep
  PalmPilot
  Rhapsody
End Enum 'SystemType

Public Class Win32_OperatingSystem

  Public BootDevice As String
  Public BuildNumber As String
  Public BuildType As String
  Public CodeSet As String
  Public CountryCode As String
  Public CurrentTimeZone As Integer
  Public Locale As String
  Public Manufacturer As String
  Public MaxNumberOfProcesses As Int64
  Public MaxProcessMemorySize As Int64
  Public Name As String
  Public NumberOfLicensedUsers As Int32
  Public NumberOfProcesses As Int32
  Public NumberOfUsers As Int32
  Public Organization As String
  Public OSLanguage As Int32
  Public OSProductSuite As Int32
  Public OSType As SystemType
  Public PlusProductID As String
  Public PlusVersionNumber As String
  Public Primary As Boolean
  Public ProductType As PlatformType
  Public RegisteredUser As String
  Public SerialNumber As String
  Public ServicePackMajorVersion As Int16
  Public ServicePackMinorVersion As Int16
  Public Version As String
  Public WindowsDirectory As String
  Friend ManagementObject As ManagementObject

  Public Overloads Shared ReadOnly Property GetList() As Win32_OperatingSystem()
    Get
      Return GetList(String.Empty)
    End Get
  End Property  'GetList

  Public Overloads Shared ReadOnly Property GetList(ByVal machineName As String) As Win32_OperatingSystem()
    Get
      Dim osClass As ManagementClass
      Dim list As New ArrayList

      If machineName.Length = 0 Then
        osClass = New ManagementClass("Win32_OperatingSystem")
      Else
        Dim path As New ManagementPath
        path.Server = "\\" & machineName.TrimStart("\") & "\root\cimv2"
        path.Path = "Win32_OperatingSystem"

        osClass = New ManagementClass(path)
      End If

      For Each osObject As ManagementObject In osClass.GetInstances()

        Dim info As New Win32_OperatingSystem

        info.BootDevice = osObject("BootDevice")
        info.BuildNumber = osObject("BuildNumber")
        info.BuildType = osObject("BuildType")
        info.CodeSet = osObject("CodeSet")
        info.CountryCode = osObject("CountryCode")
        info.CurrentTimeZone = Convert.ToInt32(osObject("CurrentTimeZone"))
        info.Locale = osObject("Locale")
        info.Manufacturer = osObject("Manufacturer")
        info.MaxNumberOfProcesses = Convert.ToInt64(osObject("MaxNumberOfProcesses"))
        info.MaxProcessMemorySize = Convert.ToInt64(osObject("MaxProcessMemorySize"))
        info.Name = osObject("Name")
        info.NumberOfLicensedUsers = Convert.ToInt32(osObject("NumberOfLicensedUsers"))
        info.NumberOfProcesses = Convert.ToInt32(osObject("NumberOfProcesses"))
        info.NumberOfUsers = Convert.ToInt32(osObject("NumberOfUsers"))
        info.Organization = osObject("Organization")
        info.OSLanguage = Convert.ToInt32(osObject("OSLanguage"))
        info.OSProductSuite = Convert.ToInt32(osObject("OSProductSuite"))
        info.OSType = Convert.ToInt32(osObject("OSType"))
        info.PlusProductID = osObject("PlusProductID")
        info.PlusVersionNumber = osObject("PlusVersionNumber")
        info.Primary = osObject("Primary")
        info.ProductType = Convert.ToInt32(osObject("ProductType"))
        info.RegisteredUser = osObject("RegisteredUser")
        info.SerialNumber = osObject("SerialNumber")
        info.ServicePackMajorVersion = Convert.ToInt16(osObject("ServicePackMajorVersion"))
        info.ServicePackMinorVersion = Convert.ToInt16(osObject("ServicePackMinorVersion"))
        info.Version = osObject("Version")
        info.WindowsDirectory = osObject("WindowsDirectory")
        info.ManagementObject = osObject

        list.Add(info)

      Next osObject

      Return list.ToArray(GetType(Win32_OperatingSystem))

    End Get
  End Property  'GetList(machine)

  Public Sub RebootMachine(ByVal system As Win32_OperatingSystem)

    system.ManagementObject.InvokeMethod("Reboot", New Object() {})

  End Sub  'RebootMachine

End Class

Sample usage:

  Dim systems() As Win32_OperatingSystem = Win32_OperatingSystem.GetList("machine name goes here")
  systems(0).RebootMachine()

Bob

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
solomonacquahAuthor Commented:
Thank You.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.