Windows Services
-
Hi, How can I start / stop a windows service from my vb application. can I get a sample Shenthil
VB6 (w/o WMI): You'll have to call into the Windows API's to get in touch with the Service Control Manager to start and stop Services. VB6 (with WMI): You can use WMI to get a list of Win32_BaseService objects. You can then use simple method calls to start and stop the service(s) you want. VB.NET: Very easy. See the documentation on the ServiceController class. RageInTheMachine9532
-
VB6 (w/o WMI): You'll have to call into the Windows API's to get in touch with the Service Control Manager to start and stop Services. VB6 (with WMI): You can use WMI to get a list of Win32_BaseService objects. You can then use simple method calls to start and stop the service(s) you want. VB.NET: Very easy. See the documentation on the ServiceController class. RageInTheMachine9532
-
Thanks. can u give me more detail about using with WMI in vb6.0. Now I am working without WMI. shenthil
VB6 with WMI: This will stop a service and it's dependants:
' The "." mean the local computer.
strComputer = "."
' We're going to stop the NetDDE service.
' First, get the list of dependent services and stop them one by one.
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery("Associators of {Win32_Service.Name='NetDDE'} Where AssocClass=Win32_DependentService Role=Antecedent")
For each objService in colServiceList
objService.StopService()
Next
' We just told the dependent services to stop. Now we'll wait about 20 seconds
' before we tell the NetDDE service to stop.
Wscript.Sleep 20000
' ...and, finally, stop the NetDDE service.
Set colServiceList = objWMIService.ExecQuery("Select * from Win32_Service where Name='NetDDE'")
For each objService in colServiceList
errReturn = objService.StopService()
NextRageInTheMachine9532