Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script won't run from Windows scheduler

Status
Not open for further replies.

JesOakley

Programmer
Jan 21, 2008
42
0
0
GB
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
Code:
 Cscript D:\perl-src\ProcessRunning.vbs //Nologo >statout6.txt
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:
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
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top