• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 322
  • Last Modified:

PSPasswd and VBScript - cannot get Wscript.Shell.Run to pipe StdOut and StdErr to files

Code snippet:
Set f_objShell = CreateObject("Wscript.Shell")
Set f_objFso = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1, ForWriting = 2, ForAppending = 8
tCommand = tCommand & " >>" & tOutFile & " 2>>" & tErrFile
	  'RUN PROGRAM
        f_objShell.Run tCommand, tShow, tWait
		wscript.echo "StdOut"
		wscript.echo f_objshell.StdOut.ReadAll
		wscript.echo "StdErr"
		wscript.echo f_objshell.StdErr.ReadAll
		ScriptPause

Open in new window


This is NOT creating either output file, nor is it populating either StdOut or StdErr.

I need to have the output from PSPasswd to determine whether the password for the specified user was changed successfully or not and cannot do that without access to the output programatically.

If I run the command from a CLI prompt, it works as expected.
0
Darrell Porter
Asked:
Darrell Porter
  • 4
  • 4
1 Solution
 
Darrell PorterEnterprise Business Process ArchitectAuthor Commented:
I have also tried the .Exec method and that also does not work.
0
 
Bill PrewCommented:
Really need to see all the code involved, but it looks like in the command you are running you are piping the STDOUT and STDERR to disk files.  Try removing those from the command line, since VBS can't grab them if you send them to disk.

~bp
0
 
Bill PrewCommented:
I think you need to use Exec to capture output into the code as well, not Run.

~bp
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Darrell PorterEnterprise Business Process ArchitectAuthor Commented:
I have tried it without piping the output to files.  Does not get the output.
I have tried the EXEC method and this is also not working (using the StdOut and StdErr methods).

If it helps, I am specifically trying to capture the output from PSPASSWD.EXE from SysInternals and parse its output.
I have Googled for a solution and have not found one which works.
I have tried using WMI as a replacement for using PSPASSWD.EXE and cannot get it to actually connect to remote systems - should I find PSPASSWD.EXE will not do what I need it to do, I will open a different question for the WMI issue.
0
 
Bill PrewCommented:
Give this a try.

Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set f_objFso = CreateObject("Scripting.FileSystemObject")
Set f_objShell = CreateObject("Wscript.Shell")
Set oExec = f_objShell.Exec tCommand
Do While oExec.Status = 0
   WScript.Sleep 10
   Do While Not oExec.StdOut.AtEndOfStream
      Wscript.Echo "StdOut"
      WScript.Echo oExec.StdOut.ReadLine
      If Not oExec.StdErr.AtEndOfStream Then
         Wscript.Echo "StdErr"
         Wscript.Echo oExec.StdErr.ReadLine
      End If
   Loop
Loop
ScriptPause

Open in new window

~bp
0
 
Darrell PorterEnterprise Business Process ArchitectAuthor Commented:
Bill, you are awesome!
I had to tweek the code you provided a bit, but once that was done, it worked like a champ!
Thank you so much!

WT
0
 
Darrell PorterEnterprise Business Process ArchitectAuthor Commented:
Bill, you're a rock star!  Thank you so much!
0
 
Bill PrewCommented:
Welcome, so glad that was useful.

~bp
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now