Samy strike back...

This story is true...

This is my almost everyday life as Windows system administrator. Only names have been changed...

Samy ;-p


Tuesday, June 8, 2010

PsExec StdOut

Tuesday, June 8, 2010
A few days ago I've to write a small VBScript in association with PsExec for executing an ms-dos on a remote computer. No issues but...
After few unsuccessful tries; no way to get the StdOut I've start finding other reason than my poor programmer knowledges. So after few search on Google, I've discover that there is a known bug on PsExec versions prior to 1.98.
As ever and as recommended by software and hardware providers always update to the latest available version of code...
So here's the link to PSTools lastest version on Microsoft website. These tools are certainly the most useful toolbox for a Windows administrator. That might explain why Microsoft has acquire Sysinternal some times ago...

If it helps, here's the script which should works with PsExec v1.98. Provided as is...

Option Explicit   
On Error Resume Next
Dim WshShell, oExec, Cmmd, CptName, UsrName, UsrPWd, PsxCmmd, PsxReturn, PSPath
Set WshShell = CreateObject("WScript.Shell")

CptName = "ComputerName"
UsrName = "UserName"
UsrPWd = "Paswword"
PsxCmmd = "ipconfig /all" ' MS-Dos command-line example
PSPath =  "C:\WINDOWS\PSTools\"

Cmmd = PSPath  & "psexec.exe \\" & CptName & " -u " & UsrName & " -p " & UsrPWd & " " & PsxCmmd
Set oExec = WshShell.Exec(Cmmd)
Do While Not oExec.StdOut.AtEndOfStream
   PsxReturn= oExec.StdOut.readall()
Loop
wScript.Echo "PSXReturn :" &PsxReturn

2 comments:

Amir Servatdjoo said...

for me, it doesn't even work with 1.98. Nothing gets returned.

Samy said...

Hi Amir

a double "" have been removed.
you can try it again. ;-)

Post a Comment