Discussion:
Monitoring a process on a server....
(too old to reply)
dnec
2007-12-20 22:22:00 UTC
Permalink
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.
Pegasus (MVP)
2007-12-20 22:44:33 UTC
Permalink
Post by dnec
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.
====================
' 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)
-s:ProcessResults -nomsg -a:" & strResultsFile
====================
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.
Having the statement "option explicit" at the start of your code
would be a wonderful thing. It would tell you immediately that
you're using the variable "Computer" in one place and "strComputer"
in another, even though the two refer to one and the same thing.
dnec
2007-12-20 23:10:01 UTC
Permalink
ok. I'll be sure to make remember that. Another source seems to indicate
that you cannot impersonate to the local computer with WMI. You can only
impersonate to a remote host. However, I'm not exactly sure what that means
and I'm not sure where to make a change if necessary.
Thanks.
Post by Pegasus (MVP)
Post by dnec
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.
====================
' 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)
-s:ProcessResults -nomsg -a:" & strResultsFile
====================
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.
Having the statement "option explicit" at the start of your code
would be a wonderful thing. It would tell you immediately that
you're using the variable "Computer" in one place and "strComputer"
in another, even though the two refer to one and the same thing.
Pegasus (MVP)
2007-12-20 23:38:47 UTC
Permalink
Maybe I did not express myself clearly. This is what your code should
look like. Spot the difference!

' 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 strComputer 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
==================
If you run the code on the local machine then you must not supply
a user name or password.
Post by dnec
ok. I'll be sure to make remember that. Another source seems to indicate
that you cannot impersonate to the local computer with WMI. You can only
impersonate to a remote host. However, I'm not exactly sure what that means
and I'm not sure where to make a change if necessary.
Thanks.
Post by Pegasus (MVP)
Post by dnec
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.
====================
' 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)
-s:ProcessResults -nomsg -a:" & strResultsFile
====================
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.
Having the statement "option explicit" at the start of your code
would be a wonderful thing. It would tell you immediately that
you're using the variable "Computer" in one place and "strComputer"
in another, even though the two refer to one and the same thing.
dnec
2007-12-21 00:11:01 UTC
Permalink
ahhh....I spotted the difference.

Now its working.

Thanks very much for your patience.
Post by Pegasus (MVP)
Maybe I did not express myself clearly. This is what your code should
look like. Spot the difference!
' 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 strComputer 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)
-s:ProcessResults -nomsg -a:" & strResultsFile
==================
If you run the code on the local machine then you must not supply
a user name or password.
Post by dnec
ok. I'll be sure to make remember that. Another source seems to indicate
that you cannot impersonate to the local computer with WMI. You can only
impersonate to a remote host. However, I'm not exactly sure what that means
and I'm not sure where to make a change if necessary.
Thanks.
Post by Pegasus (MVP)
Post by dnec
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.
====================
' 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)
-s:ProcessResults -nomsg -a:" & strResultsFile
====================
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.
Having the statement "option explicit" at the start of your code
would be a wonderful thing. It would tell you immediately that
you're using the variable "Computer" in one place and "strComputer"
in another, even though the two refer to one and the same thing.
unknown
2010-05-25 16:19:57 UTC
Permalink
There is a free monitoring tool you could use http://www.real-user-monitoring.com



dne wrote:

Monitoring a process on a server....
20-Dec-07

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.

Previous Posts In This Thread:

On Thursday, December 20, 2007 5:22 PM
dne wrote:

Monitoring a process on a server....
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.

On Thursday, December 20, 2007 5:44 PM
Pegasus \(MVP\) wrote:

Re: Monitoring a process on a server....
"dnec" <***@discussions.microsoft.com> wrote in message news:9AB64625-D44B-4D4E-8F5B-***@microsoft.com...

Having the statement "option explicit" at the start of your code
would be a wonderful thing. It would tell you immediately that
you're using the variable "Computer" in one place and "strComputer"
in another, even though the two refer to one and the same thing.

On Thursday, December 20, 2007 6:10 PM
dne wrote:

ok. I'll be sure to make remember that.
ok. I'll be sure to make remember that. Another source seems to indicate
that you cannot impersonate to the local computer with WMI. You can only
impersonate to a remote host. However, I'm not exactly sure what that means
and I'm not sure where to make a change if necessary.
Thanks.

"Pegasus (MVP)" wrote:

On Thursday, December 20, 2007 6:38 PM
Pegasus \(MVP\) wrote:

Maybe I did not express myself clearly. This is what your code shouldlook like.
Maybe I did not express myself clearly. This is what your code should
look like. Spot the difference!

' 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 strComputer 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
==================
If you run the code on the local machine then you must not supply
a user name or password.


"dnec" <***@discussions.microsoft.com> wrote in message news:6EDA26F5-7828-41AE-93EC-***@microsoft.com...

On Thursday, December 20, 2007 7:11 PM
dne wrote:

ahhh....I spotted the difference.Now its working.
ahhh....I spotted the difference.

Now its working.

Thanks very much for your patience.


"Pegasus (MVP)" wrote:


Submitted via EggHeadCafe - Software Developer Portal of Choice
LINQ With Strings
http://www.eggheadcafe.com/tutorials/aspnet/03afdcf3-7b60-47db-adb9-db7fe2c6ab8c/linq-with-strings.aspx
Peter Foldes
2010-05-26 04:40:15 UTC
Permalink
Deadhead from egghead answering to a 3yr old post
--
Peter

Please Reply to Newsgroup for the benefit of others
Requests for assistance by email can not and will not be acknowledged.
http://www.microsoft.com/protect
Post by unknown
There is a free monitoring tool you could use http://www.real-user-monitoring.com
Monitoring a process on a server....
20-Dec-07
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.
====================
' 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)
-s:ProcessResults -nomsg -a:" & strResultsFile
====================
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.
On Thursday, December 20, 2007 5:22 PM
Monitoring a process on a server....
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.
====================
' 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)
-s:ProcessResults -nomsg -a:" & strResultsFile
====================
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.
On Thursday, December 20, 2007 5:44 PM
Re: Monitoring a process on a server....
Having the statement "option explicit" at the start of your code
would be a wonderful thing. It would tell you immediately that
you're using the variable "Computer" in one place and "strComputer"
in another, even though the two refer to one and the same thing.
On Thursday, December 20, 2007 6:10 PM
ok. I'll be sure to make remember that.
ok. I'll be sure to make remember that. Another source seems to indicate
that you cannot impersonate to the local computer with WMI. You can only
impersonate to a remote host. However, I'm not exactly sure what that means
and I'm not sure where to make a change if necessary.
Thanks.
On Thursday, December 20, 2007 6:38 PM
Maybe I did not express myself clearly. This is what your code shouldlook like.
Maybe I did not express myself clearly. This is what your code should
look like. Spot the difference!
' 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 strComputer 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)
-s:ProcessResults -nomsg -a:" & strResultsFile
==================
If you run the code on the local machine then you must not supply
a user name or password.
On Thursday, December 20, 2007 7:11 PM
ahhh....I spotted the difference.Now its working.
ahhh....I spotted the difference.
Now its working.
Thanks very much for your patience.
Submitted via EggHeadCafe - Software Developer Portal of Choice
LINQ With Strings
http://www.eggheadcafe.com/tutorials/aspnet/03afdcf3-7b60-47db-adb9-db7fe2c6ab8c/linq-with-strings.aspx
David H. Lipman
2010-05-27 01:48:36 UTC
Permalink
From: "Peter Foldes" <***@hotmail.com>

| Deadhead from egghead answering to a 3yr old post

Hey, don't degrade Dead-Heads like that.
--
Dave
http://www.claymania.com/removal-trojan-adware.html
Multi-AV - http://www.pctipp.ch/downloads/dl/35905.asp
Loading...