1.

Solve : Send an ENTER command to an Executable program?

Answer»

I hope this has not been already answered in another THREAD, but here's what I really NEED to do.

I set up Microsoft's "Disk Cleanup" program to run in extended mode, for all my customers and put a shortcut to it on their desktop as a part of a weekly (not weakly) maintenance routine.

Here's the command line to run the program:
%SystemRoot%\System32\Cmd.exe /c Cleanmgr /sageset:65 & Cleanmgr /sagerun:65

And here's the batch file to run the command:

Echo off
cls
%SystemRoot%\System32\Cmd.exe /c Cleanmgr /sageset:65 & Cleanmgr /sagerun:65


But somehow, I need to get the ENTER Keypress into the program so the user doesn't have to manually click the [OK] button.

I've piped Y and N to programs before but never the "ENTER" key.
Any help would be greatly appreciated.  (I want to stay within batch file programming if possible)

What OS?


XP Pro, Vista, Win-7 or Win-8  Eh?

Batch language is pretty much the same with all of them.I would assume that is happening because you are using sageset.As far as I know, there is no generic way to pipe keypresses to Windows GUI programs. If the program was written to accept them, that's one thing, but if it wasn't, then you can send all the CRs you LIKE via a pipe

echo. | program.exe

or via a temp file using redirection

echo. >crlf & program.exe
and they will be ignored.

Cleanmgr.exe APPEARS to fall into that category pf program. I saw a post on the MSFN forum which said that there is no way to get cleanmgr to run silently. I suspect that this may be by design; that it needs 2 clicks on "OK" buttons by a logged-in user to run it. Possibly for security reasons. For a start, cleanmgr /sageset:NN modifies the registry, and I can also see how cleanmgr could be used by the ill intentioned to cover their tracks.

Quote from: TheShadow on February 19, 2012, 02:36:16 PM

XP Pro, Vista, Win-7 or Win-8  Eh?

Your "customers" run all those operating systems? Including unreleased ones? Anyhow, cleanmgr is not the same on all those OSs. Vista and 7 have new switches compared to XP.

Quote
so the user doesn't have to manually click the [OK] button.

But they are "manually" clicking the shortcut icon; their hand is on the mouse, what difference will another click or two make?

If you did a reg QUERY you could check to see if the registry entry exists already.  If it does then you don't need to use the SAGESET. Ok, I guess some clarification is needed.

My customers who I set up a weekly maintenance routine for, do use XP, Vista and Win-7 and I'm personally testing Win-8/DP, so I'm trying to find things that will work across multiple OS's.

But what I'd like to do is set up Disk Cleanup to run from a batch file, not from a desktop shortcut, so I don't have to depend on an 86 yr old gramma to do her weekly maintenance, which many of them won't.
I'd like for it to run without user intervention, just like my XPCleanup.bat program, which I do put in the Startup folder, for a little daily maid service.
I'd like to be able to add Disk Cleanup to the end of my own XPCleanup.bat program.

It's just that Disk Cleanup addresses some System Folders that I've not previously identified, to add them to my cleanup batch file.  The one I use on my own PC, is customized for my own use and has over 40 lines in it now.
When I do a cleanup, I really do a CLEANUP!
I don't mess around with it!

I did figure out how to empty the trash cans (recycle bins) with a batch file, so now I empty those too.

I'm just trying to do the best possible job for my customers, that I can do with the very minimal things for them to do.

My goal (someday) is for a totally self maintaining PC.  I use AV and AS software that updates and scans by itself every day and I have my Cleanup batch file that runs on every boot up, so the user can enjoy their PC without having to worry about the maintenance aspect of it.

thanks for all your help,
The Shadow  Quote from: Squashman on February 19, 2012, 04:19:30 PM
If you did a reg query you could check to see if the registry entry exists already.  If it does then you don't need to use the SAGESET.

Well, you're on the right track.  If I manually run sageset, then I can run Sagerun as many times as I like and still wont have to change anything.  Good point!

Yous guys have got me thinking outside the box, and for this 68 year old, that's a GOOD THING!

Cheers Mates!
The Shadow  I'm back!

Salmon Trout, if memory serves me, you've helped me out before and sure enough you've done it again.

echo. | program.exe

This suggestion of yours works perfectly.

I put the Disk Cleanup command at the end of my XPCleanup.bat  batch file and it runs without user intervention.
I did remove sageset from the command line, since the parameters only need to be set once and I can do that when I first install the batch file for my customer.

Moving right along................

Many Thanks!
The Shadow B)The reason it runs without user intervention is because you took the SAGESET out.I'm getting the WHOLE picture now. 

No, it runs automatically because of the help given to me by Salmon Trout to pipe the CR into the program when it runs.
That was a huge help that I may be able to use again.

Taking out Sageset was just a part of my learning curve.
You still have to run cleanmgr with sageset at some point to set up the choice for what things will be removed.

I know I'll get another argument about this, but I always check everything, but, Office Setup Files, Setup LOGS and Compress old files.  After I run my registry tweaks, Compress old files is not even in the list.

I'm working on a batch file to run from my Utilities disk, to install the Extended version of Disk Cleanup, into the Startup Folder,  after first running cleanmgr with sageset, to set the parameters for later running cleanmgr with sagerun.

I always try to automate the install process as much as I can to save valuable time, while at a customer's home.

I have it nailed down now.  Case Closed!

Thanks for all the help,
The Shadow 

PS: Now that I have the process nailed down for XP, I'll be working to make sure it works as well in Vista and Win-7 and Win-8.

Quote from: TheShadow on February 19, 2012, 05:02:17 PM

echo. | program.exe


Once you have done the sageset part, subsequent runs of cleanmgr /sagerun:NN should run without you doing this. (I just tried it)
I've created a batch file, to install my new XPCleanup batch file into the Startup folder.  At the end of my XPCleanup batch file is the line to automatically run Disk Cleanup (cleanmgr.exe) in the automatic mode.
Like you said, in my install batch file, I run cleanmgr with sageset to set up the things to delete and then when I run cleanmgr with only the sagerun switch, it deletes only what was previously set up with sageset.

I can minimize my XPCleanup batch file when it runs, but Disk Cleanup still pops up on-screen and runs without the user having to press the obligatory 'OK' button.  I'd rather not actually see Disk Cleanup at all, but that's OK.  I can live with that.
It's neat, clean and definitely helps to keep a PC clean and running at peak performance.
I've been working on my Cleanup.bat program since the '98 days and it's still a work in progress.  Every time a find a new hiding place for junk files, I add that location (path) to a new line in my Cleanup batch file.

This is just one little step in a whole litany of things I do to set up or tune up a PC.
My goal has been and is still to set up a PC to run at maximum efficiency from one year to the next with little or no hands-on maintenance.  Because most users just Won't Do It.

The build-up of JUNK or Crapola as I like to call it, is one of the biggest problems in any PC.
It loads up the hard drive, slows down all scans and can greatly increase the time and space to do a backup.

One of my favorite quotes is "Minus CRUD is COOL!"

Thanks again,
The Shadow B)Shadow, I can't get the pipe to work when using SAGESET.  Not sure how you are getting it to work.
Salmon Trout does it work for you when using SAGESET? Quote from: Squashman on February 20, 2012, 06:59:34 AM
Shadow, I can't get the pipe to work when using SAGESET.  Not sure how you are getting it to work.
Salmon Trout does it work for you when using SAGESET?

No; see my reply above (Post 4 of this thread). You cannot send a CR to cleanmgr via a pipe. When using /sageset it requires the OK button to be pressed. When /sageset has been used and the registry entry has been saved, then cleanmgr /sagerun:NN does not need ENTER to be sent to it, and will ignore any that are sent.


Discussion

No Comment Found