Saturday, April 19, 2014

Batch File Run as administrator Changes current or default directory to c:\windows\system32 using %CD%

In Windows Vista, Windows 7 or Windows 8 with UAC turned on, and you run the batch file with %CD% to get current directory, it actually points to C:\windows\system32. To solve this, set the following code at the beginning of your batch file.

@setlocal enableextensions
@cd /d "%~dp0"

It will change the directory or file path back to your current folder/path.


No comments: