Hi to all you scripting gurus out there.
I have a problem with a small script which I have seen all over the net (including in these hallowed Tek-Tip pages) which should tell me if a service is running.
The script is called from a bat file with the line
When the bat file is run from a CMD file it works fine, but when run from the scheduler it fails after writing the '2a' line to statout6.txt.
My investigation suggests a problem with objComputer, as any reference to it seems to cause a failure and an exit from the script.
Here is the source for your perusal/scorn:
The server is Wintel running Windows 2003 Enterprise R2 SP2.
I did originally have the server name hard-coded in, but was advised to change it for flexibility.
Curiously the code does run both scheduled and interactively on our development server, but I cannot find anyone who can tell me what the difference is between the two ostensibly identical servers.
Any help would be gratefully received
I have a problem with a small script which I have seen all over the net (including in these hallowed Tek-Tip pages) which should tell me if a service is running.
The script is called from a bat file with the line
Code:
Cscript D:\perl-src\ProcessRunning.vbs //Nologo >statout6.txt
My investigation suggests a problem with objComputer, as any reference to it seems to cause a failure and an exit from the script.
Here is the source for your perusal/scorn:
Code:
Set objSysInfo = CreateObject ("WinNTSystemInfo")
strComputerName = objSysInfo.ComputerName
Set objComputer = GetObject("WinNT://" & strComputerName & ",computer")
objComputer.Filter = Array("Service")
strServiceName = "IISADMIN"
Wscript.Echo "2a"
For Each aService In objComputer
Wscript.Echo "3"
If LCase(strServiceName) = LCase(aService.Name) Then
' Wscript.Echo aService.Name & "=" & aService.Status
If aService.Status = 4 then
Wscript.Echo "GOOD"
Else
Wscript.Echo "BAD"
End If
End If
Next
I did originally have the server name hard-coded in, but was advised to change it for flexibility.
Curiously the code does run both scheduled and interactively on our development server, but I cannot find anyone who can tell me what the difference is between the two ostensibly identical servers.
Any help would be gratefully received