reboot?

S

sam

I found reboot script at TechNet and I wonder how to apply in VB.Net?

Reboot Coding
************
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Shutdown)}!\\" & _
strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("SELECT * FROM Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
objOperatingSystem.Reboot()
Next

Questions?
********
- What namespace that I need? System.Management?
- Will this coding work in VB.Net? How? What coding should add?
- Will it work at Windows Server 2003?

I need to reboot Windows Server 2003 to clear web cache and SQL cache for
better memory management.

Please advise.

Many thanks.
 
P

Peter Proost

This should do the trick:

Public Sub RebootWindows()
Dim OpSysSet As Object
Dim OpSys As Object
OpSysSet =
GetObject("winmgmts:{impersonationLevel=impersonate,(ShutDown)}").InstancesO
f _("Win32_OperatingSystem")
For Each OpSys In OpSysSet
OpSys.Reboot()
Next OpSys
End Sub

Hth Grtz Peter
 
G

Guest

- What namespace that I need? System.Management?
Yes
- Will this coding work in VB.Net? How? What coding should add?
I have not tried it , but I dont see why it will not
- Will it work at Windows Server 2003?
I dont have as server with me to try, but again it should.

One thing to note, is that all reboot/log off API need an adminstrator login
to work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top