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.
LVL 16
Darrell PorterEnterprise Business Process ArchitectAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Darrell PorterEnterprise Business Process ArchitectAuthor Commented:
I have also tried the .Exec method and that also does not work.
0
Bill PrewIT / Software Engineering ConsultantCommented:
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 PrewIT / Software Engineering ConsultantCommented:
I think you need to use Exec to capture output into the code as well, not Run.

~bp
0
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

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 PrewIT / Software Engineering ConsultantCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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 PrewIT / Software Engineering ConsultantCommented:
Welcome, so glad that was useful.

~bp
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.