tags:

views:

25

answers:

4

I have a Batch file which I want to execute from CMD, irrespective of what path its set to.

I am looking for something like setting Environment Variables.

e.g.

VariableName: MyBatch Path: C:\MyBatch.bat

Open CMD: c:\Program Files> "I should be able to call MyBatch here"

Thanks

A: 

You could just put it in your c:\windows\system32 directory, as its always in the system path.

wfoster
Why the downvote? This is a legitimate way to accomplish the task
wfoster
Bad idea, and unless user is in Admin group, the batch file can't be put there, anyhow.
Russ
Never put user stuff into c:\Windows\System32 (regular user cannot write into that directory anyway - and for a good reason)
a_horse_with_no_name
Yeah but the question is "irrespective of what PATH is set to" all the other solutions suggest adding or modifying the path.
wfoster
A: 

You would need to set the PATH environment variable to include the path to your batch file

Russ
A: 

Set that location in your PATH environmental variable.

I wouldn't put it the root or the system directory.

I keep a directory with all my scripts in C:\DRR\CMD

and either set it in the MyComputer GUI or run at the command script:

set PATH=%PATH%;C:\DRR\CMD
Rawheiser
A: 

If you are talking Windows, then the PATH Environment variable is what you need to set.

The path where your bat file is placed should be appended to the PATH variable. In your example append "C:\;" in the value for Path environment variable.

Then you can execute MyBatch.bat from anywhere on the command line.

InSane