Solved

Need batch script to run multiple .exe's

Posted on 2011-09-22
12
462 Views
Last Modified: 2012-05-12
I have a vendor that sends us reports as .exe's. their filename changes weekly makeing normal startup scripts i use useless. Is there a way to run a folder full of .exe's all at once, then delete all the .exe's leaving behind only the txt files the .exe's produce? I'd prefer to do this with a batch file.
0
Comment
Question by:mstephenslnb
  • 6
  • 5
12 Comments
 
LVL 33

Accepted Solution

by:
knightEknight earned 400 total points
ID: 36583341
CD/D  "D:\myfolder"
for %%X in (*.exe) do  %%X
0
 
LVL 43

Assisted Solution

by:Steve Knight
Steve Knight earned 100 total points
ID: 36583343
Short answer...yes.  If you want it to read all the exe's in a dir, suggest something like this:

@Echo off
cd /d "c:\somedir\with\exesin"
for /f %%a in ('dir /b /a-d *.exe') do (
  echo Running %%a
  START /WAIT "Running %%~a" "%%~a"
  del "%%~a"
)

That should change to the dir you want, take a dir of all the exe's in that directory and run them one by one.  It will be done in alphabetical order by default so f you want them in a different order easiest is to name them 01-exeone.exe 02-exetwo.exe etc.
It run the bit between ( and ) for each exe with %%a being the name.
Steve
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 36583346
The above will run the .exe files one at a time in directory order.  To run them all at once, add the word "start" right after "do"
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 36583351
oops, meant for my previous post
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36583359
Same(ish) but different and typing at the same time there :-)
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 36583364
... and I forgot to delete them at the end, which in my version can be done with  del *.exe  after the "for" statement.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 43

Expert Comment

by:Steve Knight
ID: 36583365
I didn't didn't think running multiple exe's at the same time was the best plan since then you wouldn't know when they had completed in order to delete them like asked but if it works for you then you could do as KnightEKnight suggest then perhaps:

echo When all windows have finished press any key to delete
pause
del *.exe

Steve
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 36583369
yes, the pause is a good suggestion.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36583377
Actually I think I'd do this:

@Echo off
cd /d "c:\somedir\with\exesin"
for /f %%a in ('dir /b /a-d *.exe') do (
  echo Running %%a
  "%%~a"
  if not errorlevel1 del "%%~a"
)

which runs each one in turn.  If it returns an errorlevel suggesting it did not run right then it doesn't delete it.

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36583764
Oh well at least I got an "assist" :-)  Thanks, hope it worked for you.

Oh BTW it never hurts to give feedback ...
0
 

Author Comment

by:mstephenslnb
ID: 36712446
Kinda new to this, sorry for the lack of feedback. The quick and easy solution won out here since the basic run its doing is opening an exe or two that dumps a large sum of txt files into the root of the same folder. As such error levels and force commands weren't as needed.
Thanks Much!
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36712777
Thanks for the feedback, as long as it helped!

Steve
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now