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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems parsing output using Wshell Exec method

Status
Not open for further replies.

josephk73

Technical User
Aug 1, 2002
115
GB
Hi Guys,

I'm getting partial success running this code. Problem is that it starts off as expected, but just then hangs.

Here is the code:
Code:
Dim remoteTool
remoteTool="\\pluto\tools\psexec.exe"

StrServer="jupiter"
Call vspDel(StrServer)

Sub vspDel(StrServer)
Set objShell = WScript.CreateObject("Wscript.Shell")
Set objExecObject = objShell.Exec("%comspec% /k " & remoteTool & " \\"&StrServer& " -c -f -d c:\tools\handle.exe")

Do Until objExecObject.StdOut.AtEndOfStream
strLine = objExecObject.StdOut.ReadLine()
WScript.Echo strLine
Loop
End Sub

As I said above the code begins to work and this is the output I get:


Code:
PsExec v1.3 - execute processes remotely
Copyright (C) 2001 Mark Russinovich
[URL unfurl="true"]www.sysinternals.com[/URL]

Connecting to lon3558xns...             Starting PsExec service on lon3558xns...                                              Connecting with PsExec service on lon3558xns... Copying c:\tools\handle.exe to lon3558xns...                                        Starting c:\tools\handle.exe on lon3558xns...                                                                              
handle.exe started on lon3558xns with process ID 3644.

However after this, the program just hangs and there is not any further output.

Any help would be great.

Cheers
 
I'm not familiar with the PSExec tool, however when I've had trouble executing a command, I have usually echoed the command, so that I can test it manually.

That way I can see the result first hand and work out if there is anything wrong with the command before tearing apart my script.
 
handle is a sysinternal tool (of course now microsoft) that tells you the PID and handle assigned to a process. Armed with that info, if you have an app/file that wont close you can just close the handle and the file becomes accessible.
 
Okay guys got this sorted. Gave up trying to parse the StdOut stream directly. I ran the command through a batch file, directed output to to a text file, which I then parse.

Thanks for looking anycase.
 
Hi guys I have a problem whereby I'm making a wmi query to around 500 servers. For the most part a connection is made without a problem. However I've got one or two servers that hang at the point of connecting to the WMI service on the machine.

I've tried error trapping (see below)and now I'm really stuck, as I reckon the script neither makes or is refused a connection hence the error trapping does not work.

I guess my question is if there is a way to say give a machine say 5 seconds to respond and if it doesn't assume a connection can't be made and the script goes onto the next machine.

Anycase, enough of my rambling, here is the code snippet I'm using..

Code:
strComputer="computerA"

Call getServices(strComputer)

Sub getServices (strComputer)
bolName=False
bolFlag=False
Err.Number=0
WScript.Echo strComputer
WScript.Echo "=============="
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
[COLOR=red]it is at this point the script is hanging and never gets to the next line to test the error number.[/color]
	If Err.Number<>0 Then
	 WScript.Echo "Machine could not be contacted. Please check manually"
	 Else
	 Wscript.Echo "Machine contacted"
	End If
	
End Sub
 
i had this issue myself when using WMI queries on our servers. check these things:

1. is the server your contacting on? you might need a ping function to check. i know your thinking "GEEZ it's a server of course it's on." well you never know until you check.
2. does the server have the firewall ON preventing connection. check ICMP and RDP calls.
3. is it an NT4 server? NT4 does not support WMI.


to bypass these errors try using "On Error Resume Next." but if it's just those two servers i would just exclude it from the list. On Error Resume always masks hidden problems. hope this helps.
 
You can enable a timeout on WMI queries, however it is not configurable for a custom timeout. It will timeout in 2 minutes. I suggest you get a copy of Ed Wilson's WMI book. Be sure to check the user reviews of it on Amazon.com as I posted a line of code missing from the book.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top