@echo off :: Create a fragment containing "cd ". Code from :: http://www.ericphelps.com/batch/lines/frag-dbg.htm :: The script is in the TEMP directory, but the :: fragment will be in the WINDOWS directory so we :: know it will be in the "path". echo e 100 "cd "> %temp%\script.txt echo rcx>> %temp%\script.txt echo 3>> %temp%\script.txt echo n %windir%\poppath.bat>> %temp%\script.txt echo w>> %temp%\script.txt echo q>>%temp%\script.txt debug < %temp%\script.txt > nul del %temp%\script.txt :: Now finish off the batch file by appending the current directory truename | find ":" >> %windir%\poppath.bat