0

Possible Duplicate:
How to get folder path from file path with CMD

How can I get path to my cmd file when it runs as administrator?

Problem is:

When I run my cmd file file as admin the windows sets the current directory as c:/windows/system32, not d:/my_script for example, which is what I want. And my cmd script can't access files referenced by a short path.

Community
  • 1
  • 1
Alexander Molodih
  • 1,928
  • 2
  • 20
  • 30
  • @AndriyM, nothing same. Problem appears in runing script as admin. – Alexander Molodih Nov 23 '11 at 20:32
  • 1
    I admit, that detail of your problem is something I cannot fathom at the moment. But both the question that I linked and the accepted answer are about how to obtain path to the batch/cmd file being executed, which seemed to me the essence of your question. @Werner Henze's answer is also about that, only it uses a somewhat unusual trick, possibly because Werner, too, didn't hear about `%~dp0`. – Andriy M Nov 23 '11 at 20:56

1 Answers1

1

In my bat-files I am using

echo %0%\..\
dir %0%\..\

which outputs

C:\tmp\t.bat\..\
...output of dir, directory listing...

Suprisingly (at least for me) a dir works this way. I would have expected this to be an invalid path because t.bat is a file and not a directory where you can go up using "..".

Werner Henze
  • 16,404
  • 12
  • 44
  • 69