|
-
Oct 5th, 2000, 01:49 PM
#1
Thread Starter
New Member
Is there a way to stop an "NT Service" from a VB app?
Thanks
-
Oct 5th, 2000, 04:08 PM
#2
Lively Member
Sure! But not just any service. You can do this with the
WMI classes. Specifically, using the Win32_Service class
and it's StopService method.
Of course you need administrator rights to do this on NT/2000 - don't know about 9x.
Here's an ex. of how to enumerate the services.
Code:
Public Sub listServices(Optional strServer As String = ".")
Dim objs As WbemScripting.SWbemObjectSet
Dim obj As WbemScripting.SWbemObject
Dim svcs As WbemScripting.SWbemServices
Dim swLocator As WbemScripting.SWbemLocator
Set swLocator = New WbemScripting.SWbemLocator
Set svcs = swLocator.ConnectServer(strServer)
Set objs = svcs.InstancesOf("Win32_Service")
Debug.Print Chr(10)
For Each obj In objs
Debug.Print "Display Name: " & obj.Properties_.Item("DisplayName")
Debug.Print "ProcessId: " & obj.Properties_.Item("ProcessId")
Debug.Print "StartMode: " & obj.Properties_.Item("StartMode")
Debug.Print "SystemName: " & obj.Properties_.Item("SystemName")
Debug.Print "StartName: " & obj.Properties_.Item("StartName")
Debug.Print "Can be Stopped: " & obj.Properties_.Item("AcceptStop")
Next obj
Set objs = Nothing
Set svcs = Nothing
Set swLocator = Nothing
End Sub
Once you've got the Win32_Service Object for the service you want to stop just call the StopService method.
It's def is simply - Service.StopService() As Integer
good luck.
C/C++,Delphi, VB6,Java,PB (blech!),ASP,JSP,SQL...bla bla bla and bla
I love deadlines. I like the whooshing sound they make as they fly by.
—Douglas Adams
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|