How to execute programs in the same directory as the windows batch file?
I have a .bat
and a .exe
file in the same folder. I want to call the .exe
file from the .bat
, but for that I need to put the full absolute path to it. The best way to accomplish this without inputting the full path to the .exe
is as follows:
Call the .exe
with %~dp0
, like this: %~dp0MyProgram.exe
.
%0
contains the full path to the called .bat
file.
~dp
says to get the drive and path, including trailing \
.
For example: I have the setup file vs_professional.exe (Visual Studio 2017 Pro) in a folder with the batch file. The batch file contains the single line below to call out the .exe
with the additional executable options:
"%~dp0vs_professional.exe" --noweb --add Microsoft.VisualStudio.Workload.ManagedDesktop --add Microsoft.VisualStudio.Workload.NetWeb --add Component.GitHub.VisualStudio --includeOptional
To run the above install with those options just right-click on the batch file and select “Run as administrator”.