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

Any way to pipe a y<enter> response to Wshell.Run?

Status
Not open for further replies.
Feb 11, 2005
153
US
Okay I am running something remotely and the ONLY way I have been able to do this successfully is the following -

WshShell.Run "C:\psexec.exe \\" & strDeviceName & " -i C:\Delprof\Delprof.exe /q /i /d:10", 1, True

The problem is in psexec the delprof runs but requires a y response and an enter. (I am thinking it psexec not like the /q switch on delprof)


Is there any way to pipe a response to this prompt?

I ultimately want to delete all profiles older than 10 days from any remote computer this is ran against. ALso I am developing this because the few pages I have seen do not take into account all the variables.

E.G. this solution

does not take into account days in the cmdString = "delprof /p /c:\\" &strComputerName line though I fgured out a way to get days into it putting /d:10 before the /c: there are 2 problems I have to put delprof local on the PC I am running it from (I want it on a server) and the next line that says its completed won't wait until this is done (even when I tried to put a ,1 ,True at the end of the Run line.

Ultimately what I would like is this and eliminate psexec.exe altogether.

WshShell.Run "\\" & strServer & "\netadmin\Remote Profile Cleanup Script\Delprof\delprof /q /i /d:10 /c:\\" &strDeviceName,1 ,True

but that says I have not terminated the string eg no " before the first " but if I put in a ' this then yields more errors.

Hence why I went the psexec route in the first place.

Thoughts? Suggestions?
 
Firstly, once you kick off the exe via psexec, there is no way to access STDIN. There are a few things to consider. First, you could play around with double quoting the command. That may get the /q parameter through for you. Next, you could consider copying a vbscript to the remote machine that will run delprof for you. Then in that script you could use .Exec then you would have access to STDIN.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
>WshShell.Run "\\" & strServer & "\netadmin\Remote Profile Cleanup Script\Delprof\delprof /q /i /d:10 /c:\\" &strDeviceName,1 ,True
[tt]WshShell.Run "[red]""[/red]\\" & strServer & "\netadmin\Remote Profile Cleanup Script\Delprof\delprof[red]""[/red] /q /i /d:10 /c:\\" &strDeviceName,1 ,True[/tt]
In any case, delprof can run remotely.
 
Thanks guys.... EBGreen I will keep this doublequote idea in mind I have had other scripting problems in the past this may have fixed for me.

No matter how hard I tried to get this script to run delprof off the seerver it didn't work....
When I did -

WshShell.Run """\\" & strServer & "\netadmin\Remote Profile Cleanup Script\Delprof\delprof"" /q /i /d:10 /c:\\" &strDeviceName,1 ,True

I got no script errors but it just would not run delprof - No prompt box or anything
So I ended up doing a

objFSO.CopyFolder "\\" & strServer & "\netadmin\Remote Profile Cleanup Script\Delprof" , "C:\Delprof" , OverWriteFiles
WshShell.Run "C:\Delprof\delprof /q /i /d:10 /c:\\" &strDeviceName ,1 ,True
objFSO.DeleteFolder "\\" & strDeviceName & "\C$\Delprof" , True

While a little less ideal the script does actually run quite efficently so I guess theres more than one way to milk a goat.
 
Did you try the equivalent of
Code:
echo y|del *.*

So, [del *.*] would first ask "Are you sure (y/n)?" before going ahead but by providing [echo y|] in front of it provides the yes response...

So I'm guessing
Code:
WshShell.Run "cmd /c echo y|C:\psexec.exe...
will work (or perhaps not if the command is running remotely).

Just a thought...

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top