Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reboot Machine with VB.NET 1

Status
Not open for further replies.

reffek

Programmer
Apr 7, 2005
24
0
0
US
What code would you use to reboot a maching using VB.NET?
 
Windows has a built in .exe called shutdown. If you go to the command prompt and run "shutdown -?", you should be able to see a list of all valid switches.

I haven't tried this code out, but it should give you the general idea.

Code:
System.Diagnostics.Process.Start("shutdown -r")

or

Code:
Shell("shutdown -r")

Jay
 
Of course it is not working. You need to pass the "-r" as an argument, so:

Code:
System.Diagnostics.Process.Start("shutdown", "-r")

-bclt
 
It seems c:\windows\system32\shutdown.exe exists in WinXP but not in Win2K. Any suggestions for VB.NET rebooting under Win2K?
 
You have to add a reference to the management. Found this, but not tested:

Code:
Dim result As Int32
result = 0
Dim scope As New Management.ManagementScope( _
"\\localhost\root\cimv2")

scope.Options.EnablePrivileges = True
scope.Connect()
Dim oq As New System.Management.ObjectQuery( _
"SELECT * FROM Win32_OperatingSystem")

Dim query1 As New Management.ManagementObjectSearcher(scope, oq)

Dim queryCollection1 As Management.ManagementObjectCollection = query1.Get()
Dim mo As Management.ManagementObject
For Each mo In queryCollection1

Dim ss As String() = {"6", "0"}

mo.InvokeMethod("Win32Shutdown", ss)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top