Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 500
  • Last Modified:

Need batch script to run multiple .exe's

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
mstephenslnb
Asked:
mstephenslnb
  • 6
  • 5
2 Solutions
 
knightEknightCommented:
CD/D  "D:\myfolder"
for %%X in (*.exe) do  %%X
0
 
Steve KnightIT ConsultancyCommented:
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
 
knightEknightCommented:
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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
knightEknightCommented:
oops, meant for my previous post
0
 
Steve KnightIT ConsultancyCommented:
Same(ish) but different and typing at the same time there :-)
0
 
knightEknightCommented:
... and I forgot to delete them at the end, which in my version can be done with  del *.exe  after the "for" statement.
0
 
Steve KnightIT ConsultancyCommented:
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
 
knightEknightCommented:
yes, the pause is a good suggestion.
0
 
Steve KnightIT ConsultancyCommented:
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
 
Steve KnightIT ConsultancyCommented:
Oh well at least I got an "assist" :-)  Thanks, hope it worked for you.

Oh BTW it never hurts to give feedback ...
0
 
mstephenslnbAuthor Commented:
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
 
Steve KnightIT ConsultancyCommented:
Thanks for the feedback, as long as it helped!

Steve
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now