dnec
2007-12-20 22:22:00 UTC
I've got a script I'm working on but I've run into an error. I'm trying to
monitor a process on remote servers (its the same process for all three), and
if the process ever ends I'd like this script to run a command line email
program called Postie. Notifying me the process has stopped.
Unfortunately I've got to embed the credentials within the script. I'm
currently logged on as myself under XP (trying to develop the script), not
the user embedded within the script. Once I get the script working I'll
transfer it to a WIN2K3 server and, using Windows Task Scheduler, have it run
intermittently throughout the day. The credentials that are embedded ARE
local admins on the respective servers.
Here's the code that's been developed so far:
====================
' Create Objects
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")
' Create Variables
arrComputer = array("Computer1","Computer2","Computer3")
strProcess = "Process.exe"
strUser = "domain\username"
strPassword = "respective_password"
strResults = ""
strResultsFile = "C:\Windows\output.txt"
' Process Each Computer
For Each Computer in arrComputer
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objSWbemLocator.ConnectServer(strComputer, _
"root\CIMV2", strUser, strPassword, "MS_409", "NTLMDomain:" +
strDomain)
Set colProcesses = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = '" & strprocess & "'")
' Only Log if Process Not Running
If colProcesses.Count = 0 Then
strResults = strResults & Computer & "," & strProcess & "," & " Not
Running" & vbCrLf
End If
Next
'Write Process Results to File
Set logFile = objFSO.CreateTextFile(strResultsFile, True)
logFile.WriteLine strResults
logFile.Close
'Email Results (Modify this line as needed, if you can send a text body
' as a parameter, then you won't need to create the results
file)
objShell.Run "postie -host:mailserver.com -from:***@here -to:***@there
-s:ProcessResults -nomsg -a:" & strResultsFile
====================
However, when I try to run it I get the following error message:
Script: c:\documents and settings\user\desktop\scripts\XXXXXX.vbs
Line: 16
Char: 5
Error: User credentials cannot be used for local connections
Code: 80041064
Source: SWbemLocator
I'm not entirely sure why I'm getting this error, so any help would be
greatly appreciated.
thx.
monitor a process on remote servers (its the same process for all three), and
if the process ever ends I'd like this script to run a command line email
program called Postie. Notifying me the process has stopped.
Unfortunately I've got to embed the credentials within the script. I'm
currently logged on as myself under XP (trying to develop the script), not
the user embedded within the script. Once I get the script working I'll
transfer it to a WIN2K3 server and, using Windows Task Scheduler, have it run
intermittently throughout the day. The credentials that are embedded ARE
local admins on the respective servers.
Here's the code that's been developed so far:
====================
' Create Objects
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")
' Create Variables
arrComputer = array("Computer1","Computer2","Computer3")
strProcess = "Process.exe"
strUser = "domain\username"
strPassword = "respective_password"
strResults = ""
strResultsFile = "C:\Windows\output.txt"
' Process Each Computer
For Each Computer in arrComputer
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objSWbemLocator.ConnectServer(strComputer, _
"root\CIMV2", strUser, strPassword, "MS_409", "NTLMDomain:" +
strDomain)
Set colProcesses = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = '" & strprocess & "'")
' Only Log if Process Not Running
If colProcesses.Count = 0 Then
strResults = strResults & Computer & "," & strProcess & "," & " Not
Running" & vbCrLf
End If
Next
'Write Process Results to File
Set logFile = objFSO.CreateTextFile(strResultsFile, True)
logFile.WriteLine strResults
logFile.Close
'Email Results (Modify this line as needed, if you can send a text body
' as a parameter, then you won't need to create the results
file)
objShell.Run "postie -host:mailserver.com -from:***@here -to:***@there
-s:ProcessResults -nomsg -a:" & strResultsFile
====================
However, when I try to run it I get the following error message:
Script: c:\documents and settings\user\desktop\scripts\XXXXXX.vbs
Line: 16
Char: 5
Error: User credentials cannot be used for local connections
Code: 80041064
Source: SWbemLocator
I'm not entirely sure why I'm getting this error, so any help would be
greatly appreciated.
thx.