Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get path of batch file that is running

Status
Not open for further replies.

castout

Programmer
Jan 22, 2002
23
US
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.
 
This doesn't give you the path but you can use .\ so you don't need to enter the full path.

eg

copy .\*.* c:\temp

This way it doesn't matter where you run this copy from it will take .\ as your path at the moment. New Zealand, a great place to visit.
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top