Windows scripting host - Checking a service in Windows NT 4 
Author Message
 Windows scripting host - Checking a service in Windows NT 4

Hi I need some help. Has anyone created a script which can check if a
service running in Winnt 4 has stopped and if it has stopped the script will
restart it.

Thanks

Ben



Wed, 19 Oct 2005 00:28:12 GMT  
 Windows scripting host - Checking a service in Windows NT 4

Quote:

> Hi I need some help. Has anyone created a script which can check if a
> service running in Winnt 4 has stopped and if it has stopped the script will
> restart it.

Hi

Why check if it is started at all? Just use WSH's Run method and shell out to
run "net start servicename". No harm is done if the service is already running:

C:\>net start fax
The Fax Service service is starting.
The Fax Service service was started successfully.

C:\>net start fax
The requested service has already been started.

--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter



Wed, 19 Oct 2005 00:52:33 GMT  
 Windows scripting host - Checking a service in Windows NT 4

Download the free "Scriptomatic Tool" from microsoft and the "System
Administration Scripting Guide", it has over 20 examples of how to manage
services.  Or you can easily find them online (this took me about 30 seconds
to find)

http://www.microsoft.com/technet/scriptcenter/services/ScrSvc21.asp

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
 ("Select * from Win32_Service Where State = 'Stopped' and StartMode = " _
     & "'Auto'")
For Each objService in colListOfServices
    objService.StartService()
Next


Quote:

> Hi I need some help. Has anyone created a script which can check if a
> service running in Winnt 4 has stopped and if it has stopped the script
will
> restart it.

> Thanks

> Ben



Wed, 19 Oct 2005 00:57:05 GMT  
 Windows scripting host - Checking a service in Windows NT 4

Quote:

> Download the free "Scriptomatic Tool" from microsoft and the "System
> Administration Scripting Guide", it has over 20 examples of how to manage
> services.  Or you can easily find them online (this took me about 30 seconds
> to find)

> http://www.microsoft.com/technet/scriptcenter/services/ScrSvc21.asp

> strComputer = "."
> Set objWMIService = GetObject("winmgmts:" _
>     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Hi

One downside, you will need to install the WMI Core on the NT4 computer for this
to work. Also, if you want to use ADSI and the WinNT provider to handle the the
service, you will need to install the DSClient :(

--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter



Wed, 19 Oct 2005 01:01:46 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Problems Installing Windows Script 5.0 and Windows Script Host 2.0 Beta on Windows NT 4.0

2. Research: Windows Script Host or Windows Scripting Host

3. Announce: Windows NT Service Host

4. Windows Scripting Host (FSO) / Problems with NT

5. Can't register Windows Scripting Host with Windows 7

6. NT Service: An OLE Control for Creating Windows NT Services in Visual Basic (MSDN article)

7. NT Service: An OLE Control for Creating Windows NT Services in Visual Basic (MSDN article)

8. NT Service: An OLE Control for Creating Windows NT Services in Visual Basic (MSDN article)

9. Windows Scripting Host on Windows 95 OSR2

10. Windows 95 OSR1 and Windows Scripting Host

11. Windows Scripting Host for Windows 98 Book

12. Windows NT service

 

 
Powered by phpBB® Forum Software