Manage NT services with WMI/WBEM 
Author Message
 Manage NT services with WMI/WBEM

Hello,

I try to write a VB script to manage services on NT 4 (SP5) via WMI/WBEM. I
can list services and get their current status, i.e. stopped or running.

However, stopping or starting a service fails. Here is an example how I try
it:

set
svc=GetObject("winmgmts:{impersonateLevel=impersonate}").ExecQuery("select *
from Win32_Services where Name='SNMP'")

A svc.Count correctly returns: 1

If I call:                  svc.StopService()

I get return code 3 and the service still runs.

I also would like to be able to manage services remotely, with something
like:

set
svc=GetObject("winmgmts:{impersonateLevel=impersonate}!//f2411bxs").ExecQuer
y("select * from Win32_Services where Name='SNMP'")

f2411bxs  is the name of the remote host.

I have WMI 1.1 core and SDK on all systems involved installed.

Any info or tips would be appreciated.

Thanks,
Bernd



Sat, 06 Jul 2002 03:00:00 GMT  
 Manage NT services with WMI/WBEM

Quote:
> Hello,

> I try to write a VB script to manage services on NT 4 (SP5) via WMI/WBEM. I
> can list services and get their current status, i.e. stopped or running.

> However, stopping or starting a service fails. Here is an example how I try
> it:

> set
> svc=GetObject("winmgmts:{impersonateLevel=impersonate}").ExecQuery("select *
> from Win32_Services where Name='SNMP'")

> A svc.Count correctly returns: 1

> If I call:                  svc.StopService()

> I get return code 3 and the service still runs.

> I also would like to be able to manage services remotely, with something
> like:

> set
> svc=GetObject("winmgmts:{impersonateLevel=impersonate}!//f2411bxs").ExecQuer
> y("select * from Win32_Services where Name='SNMP'")

> f2411bxs  is the name of the remote host.

> I have WMI 1.1 core and SDK on all systems involved installed.

> Any info or tips would be appreciated.

> Thanks,
> Bernd


Here is a sample of starting and stopping..

Dim ServerName
Dim ServiceSet
Dim Service
Dim svcState

ServerName = InputBox("Enter the NetBIOS Name of the Server you would_
like")

Set ServiceSet = GetObject("winmgmts:
{impersonationLevel=impersonate}!//" & servername).ExecQuery("select _  
* from Win32_Service")

For each Service in ServiceSet

WScript.Echo Service.Description & " is " & Service.State

If Service.State = "Running" Then 'Wscript.Echo Service.State

svcState = InputBox("Would you like to stop this service? " & (Chr(13)_
& Chr(10)) & "Yes or No" & (Chr(13) & Chr(10)) & "Quit to Exit","Stop_
Service: " & Service.Description,"No")

If svcState = "Yes" Then
Wscript.Echo "Stopping " & Service.Description
Service.StopService()

ElseIf svcState = "Quit" Then
Exit For
Else
End If
End If

Next



Sun, 07 Jul 2002 03:00:00 GMT  
 Manage NT services with WMI/WBEM

Hi,
Trie this it works for me.
I put your service name in, but I tested it
with another service.

Set services =
GetObject("winmgmts:{impersonationLevel=impersonate}!").ExecQuery("selec
t * from Win32_Service where Name='SMNP'")

for each svc in services
        WScript.echo svc.Name, svc.State
        if svc.State = "Stopped" Then
                svc.StartService
        else
                svc.StopService
        end if
next

Quote:
> -----Message d'origine-----

> Publi : mercredi 19 janvier 2000 04:51
> Publi dans : wsh
> Conversation : Manage NT services with WMI/WBEM
> Objet : Manage NT services with WMI/WBEM

> Hello,

> I try to write a VB script to manage services on NT 4 (SP5)
> via WMI/WBEM. I
> can list services and get their current status, i.e. stopped
> or running.

> However, stopping or starting a service fails. Here is an
> example how I try
> it:

> set
> svc=GetObject("winmgmts:{impersonateLevel=impersonate}").ExecQ
> uery("select *
> from Win32_Services where Name='SNMP'")

> A svc.Count correctly returns: 1

> If I call:                  svc.StopService()

> I get return code 3 and the service still runs.

> I also would like to be able to manage services remotely,
> with something
> like:

> set
> svc=GetObject("winmgmts:{impersonateLevel=impersonate}!//f2411
> bxs").ExecQuer
> y("select * from Win32_Services where Name='SNMP'")

> f2411bxs  is the name of the remote host.

> I have WMI 1.1 core and SDK on all systems involved installed.

> Any info or tips would be appreciated.

> Thanks,
> Bernd




Sun, 07 Jul 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Using WMI to obtain dependent services (restarting services and all dependent services)

2. VB/VBS WMI&WBEM HELP!!

3. win2k resource kit VBS files do not work with WMI or WBEM

4. WMI / WBEM references

5. Managing FAX Service?

6. Managing Services Using ADSI

7. Administer/manage servers and services in domain.

8. NT - Follow Link - NT Messenger Service

9. programmatically managing users in NT

10. NT Event Log manage

11. Manage the NT Event Log Via WSH

12. Detecting if a Service is running with WMI / wbemcore.exe / ADSI

 

 
Powered by phpBB® Forum Software