If I am running a batch file (ex: c:\temp\mybatch.bat), is there a command that I can put in that batch file that will return the directory where it is located (c:\temp)?
The closest I can think of is to pull the info from the title of the directory listing. With your example, this line
DIR %0.BAT | FIND "Directory"
will return
Directory of C:\temp
Using the replaceable parameter for the batch file name allows the command to be used in any file without modification. I don't know of any way to parse the result to extract just the directory name, but the output could be sent to a file for further manipulation.
Thanks for the response, however it did not work for what I need.
The problem is that I am calling the batch file from a link on a web page, so the directory of the command window is not the same as the directory of the batch file.
If you are using an internal IIS server for your web page there is a 'bug' in IIS which you may be able to use.
The bug/hack is a UNC buffer over-run which allows you to execute command line calls OUTSIDE of the IIS tree. ie you can execute a command like SHUTDOWN.EXE and it will run as if the command was typed into a command prompt window.
If you think this will help re-post and I can email you the hack. I don't want to be seen posting hack "how to's" in a forum.
If this webserver is on the Internet you should be protected from this hack by patching your server. New Zealand, a great place to visit.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.