IT Masters LTD
  • Home
  • Online Payment
  • Remote Support
  • Knowledge Base

How to execute programs in the same directory as the windows batch file?

Created OnAugust 11, 2020
Last Updated OnAugust 11, 2020
byadmin
You are here:
  • Main
  • Software
  • Microsoft
  • How to execute programs in the same directory as the windows batch file?
< All Topics

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”.

Next How to fix Windows Activation Error 0x8007232b
Table of Contents
Leesburg, VA
Email us

Ⓒ 2015 IT Masters Ltd