Re-Post of WMI Win32_Process problem

K

kanthrc

Hi all,


I had written this script to execute commands on a remote machine. My
remote machine is running Windows XP (NO SP) & my controller machine --
from where I am issuing commands -- is running Win2k3 SP1.


Here is the script:
'Starts Here
Dim IPAddress, TargetPath, CompStatus
Set colNamedArguments = WScript.Arguments.Named
IPAddress = colNamedArguments.Item("IP")
TargetPath = colNamedArguments.Item("CMD")


Remote_Run_CMD


Sub Remote_Run_CMD
strComputer = IPAddress
System_Check(strComputer)
If (CompStatus <> 0) Then
WScript.Echo "Remote System " & strComputer & "is not reachable"
Else
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2:Win32_process")
TargetPath = "cmd.exe /c " & TargetPath
WScript.Echo "Executing: " & TargetPath & " on: " &
strComputer
int errReturn = objWMIService.Create(TargetPat­h,
Null,Null,intProcID)
If errReturn<>0 Then
WScript.Echo "Command could not be Executed on " &
strComputer
Else
WScript.Echo "Command was successfully Executed on " &
strComputer
End If
End If
End Sub


Function System_Check(strComputer)
Set objWMIService = GetObject("winmgmts:\\.\root\c­imv2")
Set colItems = objWMIService.ExecQuery("Selec­t * from
Win32_PingStatus " & "Where Address = '" & strComputer & "'")
For Each objItem in colItems
If objItem.StatusCode = 0 Then
WScript.Echo "Remote Computer " & strComputer & " is reachable. "

CompStatus = objItem.StatusCode
Else
WScript.Echo "Remote computer " & strComputer & " is not
reachable. "
CompStatus = objItem.StatusCode
End If
Next
End Function


'Ends Here


I have two questions around this script.
1. Works only with some set of commands like:
rexec.vbs /ip:10.1.1.1 /cmd:"ipconfig /all >
c:\test\ipconfig.txt"
rexec.vbs /ip:10.1.1.1 /cmd:"md c:\testfolder"
rexec.vbs /ip:10.1.1.1 /cmd:"netsh show helper >
c:\test\nethelper.txt"
But commands like,
rexec.vbs /ip:10.1.1.1 /cmd:"net use /? > c:\test\netuse.txt"

rexec.vbs /ip:10.1.1.1 /cmd:"net use * \\10.1.1.100\share
/user:administrator XyX001"
rexec.vbs /ip:10.1.1.1 /cmd:"logoff.exe"
are not at all working. File name mentioned in the command-line gets
created but will only be 0 Bytes.
Any ideas why the above three commands are not working?


2. How can I capture the output of above command execution on remote
machines? For example, rexec.vbs /ip:10.1.1.1 /cmd:"net use *
\\10.1.1.100\share /user:administrator XyX001" would return a string
with the mapped drive letter. I want to be able to capture that output
and display it to the remote user who is executing the commands. Is
this possible?


Thanks for you time,
RKC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top