Tuesday, May 7, 2019

While running a batch file in Windows 7 with Admin rights from a thumb drive, how can I get the file path back to the thumb drive?


I have a piece of software that is being distributed to several departments for installation onto Windows 7 laptops. They install software from the thumb drive and then they have to run a script to properly configure the software.


Because the script is changing registry files and program files, it requires Admin rights. When running as Admin, it drops into the System32 folder and I no longer have an easy scriptable way to access files that need to be copied from the thumb drive, simply because I don't know for sure what drive letter its going to use on the various machines. Previous installations were on Windows XP and the command window file path stayed within the script folder.


I've found similar questions here and I have already tried Relative Paths, but it can't seem to find the proper folder on the thumb drive or I can't seem to find the proper way to format it.


Answer



%~dp0 is the path containing the batch file.


For Example: if your script is g:\scripts\batch.cmd then %~dp0 is equivalent to g:\scripts\


So if all of your files are in a folder g:\scripts\files then you could refer to them with %~dp0files\filename.fileextension


also %~d0 would be just the drive g: in the example above


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...