Auto-detect batch file launch directory

If you use Batch Files to launch executable files, particularly installs, you might want to know about the string %~dp0, which Microsoft calls a modifier. This string acts like a variable and will expand to form the drive letter and path of the directory from which it is launched.
If you have a series of EXE files you want to launch, you can do this in many ways. I prefer to keep a single batch file in the same directory as the EXE and then use this to launch the EXE file. Then I can stack up as many of these as needed for a particular bulk install.
Getting back to the %~dp0 modifier. For example, to install the latest Adobe Reader silently, I use this syntax.
exit
The prefix string %~dp0 allows me to move the install directory containing the batch file and executable to any server without having to edit a path on the front of the EXE file name.
What do those five characters do exactly? Check out this page from Microsoft where it is all explained.
All content is copyright © CAD PANACEA 2005-2012 unless otherwise noted.
All content of CAD PANACEA is solely my own personal thoughts and opinions and do not those of any other entity or person.
All comments posted to this blog are the sole responsibility of the person making the comment.
Google, as a third party vendor, uses cookies to serve ads on this site. Google's use of their cookies enables it to serve ads to users based on their visit to your sites and other sites on the Internet. You may opt out of the use of these cookies by visiting the Google ad and content network privacy policy.

Recent comments