-1

Have a look at my batch file below. As you can see, I'm a pretty novice scripter. But, here is what I'm trying to accomplish.

Create a TEMP folder to copy another folder and its contents from a server to another server. Then copy folder contents, that much works. But the START of the first .exe provides me a need to answer 2 question. They need to be answered as a keypress of 1, and the second question needs a 0 to be entered, then the AppRemover6.exe will run. I've tried to use echo but I'm missing something or syntax is incorrect.

I also want the first exe to finish completely before going to the next exe.

As for the reg file, a windows pop-up needs to be answered automatically with an answer (mouse click) of YES to make the registry change.

@ECHO OFF
MD -P C:\TEMP
XCOPY "\\mybigserver\Apps\AppCleanerUtils" C:\TEMP /E /I
START /D "C:\TEMP\AppCleanerUtil6" AppRemover6.exe
START /D "C:\TEMP\AppCleanerUtil6" PatchRegistry.reg 
START /D "C:\TEMP\C:\TEMP\AppCleanerUtil5" AppRemover5.exe 
RMDIR /S /Q "C:\TEMP\AppCleanerUtil6"
RMDIR /S /Q "C:\TEMP\AppCleanerUtil5"

If there is a better way to do this?

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
  • 2
    What do you believe the `-P` switch on `MD` does? Please post the `ECHO` command you tried and the results. – lit Apr 20 '16 at 19:09
  • I believed the -P was going to check if the folder existed, and not create it if it were there. None the less, even if it is there it will put the folders I copied into a C:\TEMP. I've tried echo < myanswers.txt with a 0,1 also an echo:0,1 but that did not work for me the way I did it. Thank you for the help. – T.J. Williams Apr 21 '16 at 14:37

2 Answers2

0

many questions so for first finish before start next use:

START /WAIT ...

for passing parameters to your app try advice of empty argument "" from here: Using the "start" command with parameters passed to the started program

Community
  • 1
  • 1
Drako
  • 773
  • 10
  • 22
  • This edit was correct for me, I was able to enter in a line like so on each START: `START /WAIT /D "C:\TEMP\AppCleanerUtil6" AppRemover6.exe` `START /WAIT /D "C:\TEMP\AppCleanerUtil6" PatchRegistry.reg ` `START /WAIT /D "C:\TEMP\C:\TEMP\AppCleanerUtil5" AppRemover5.exe` Now, I had to manually enter 1, then 0 in the command box, and when it finished I had to hit ENTER to make it end, close the box, and go to the next START in the code. So that seems to work as intended. Next, the correct way to pass a 1,0,enter key press to finish the program, and go to the next one. – T.J. Williams Apr 21 '16 at 14:32
  • @T.J. Williams for correct way passing params to your AppRemover6.exe if does not take general way with "" before command and params at the end as per link in my answer, You can try running it from cmd with /? and see what options it offers; but it will be specific for your app, I don't have it, so cannot help with testing there, but still - if any question - just ask – Drako Apr 22 '16 at 05:56
0

There is no -P switch on the MD command. Even if there were, it is not needed. Windows already has a TEMP variable that should be used.

If the AppRemover6.exe program does not read from stdin, then redirecting a file to it will not work. Does AppRemove6.exe have any command line parameters that would tell it to read input from a file?

Try getting it to work directly from the cmd prompt. Create a file with the two items that must be entered.

=== response.txt
0
1

AppRemover6.exe <response.txt

If it were me, I would make these changes.

@ECHO OFF
XCOPY "\\mybigserver\Apps\AppCleanerUtils" "%TEMP%" /E /I
START /WAIT /D "%TEMP%\AppCleanerUtil6" AppRemover6.exe
START /D "%TEMP%\AppCleanerUtil6" PatchRegistry.reg
START /D "%TEMP%\C:\TEMP\AppCleanerUtil5" AppRemover5.exe
RMDIR /S /Q "%TEMP%\AppCleanerUtil6"
RMDIR /S /Q "%TEMP%\AppCleanerUtil5"
lit
  • 14,456
  • 10
  • 65
  • 119
  • `AppRemover6.exe – T.J. Williams Apr 21 '16 at 17:59
  • Please comment out or remove `@ECHO OFF` to see if it will reveal anything more about which file cannot be found. In which directory is the `response.txt` file located? – lit Apr 21 '16 at 20:21
  • The response.txt is in the same directory as the exe. I'll turn echo on and see what it shows. – T.J. Williams Apr 21 '16 at 21:36
  • I figured out, the file not being found was just a line of code with an extra quote. Just bad syntax. Nothing comes up with echo on that reveals an issue. I think it's all about the exe, and how to pass those answers. – T.J. Williams Apr 24 '16 at 19:41