We help IT Professionals succeed at work.

How to execute my own exe program under cmd without path?

chenyuhao88 used Ask the Experts™
Dear All,

We all know when we go to CMD mode(dos), if we want to execute command like "dir" we don't need to specify path. Then how could I do it with my own exe program?

Thanks heaps!
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Expert of the Quarter 2010
Expert of the Year 2010

You first need to add your program to the system environment path.
Expert of the Quarter 2010
Expert of the Year 2010
Right-click on My Computer, click Properties.
Then click on 1, select 2, click on 3, and change 4.

At 4, add a semicolon, then the location of your exe program.


was: C:\windows;C:\windows\system23
to: C:\windows;C:\windows\system23;C:\program files\my\app
You need to add the program to the path as mentioned above to do this Right-Click on My Computer->Properties->Advanced Tab->Environment Variables. You will see a system variable for path. This will be a listing of fodlers sepaerated by seim-colons (;), just add the path to the directory where the program in question lives and you will then be able to access it just by typing the name in a command window or 'Run' prompt.
You can merely specify the path as part of the filename when you run your program from DOS.

So, if your program is named 'PROGRAM.EXE' and you have saved it to a folder named 'Files\Utilities\' on say drive 'C:' then, in DOS, instead of just entering the command:


You would enter the followinf (full) command instead:


I have enclosed the whole thing in double-quotes incase there are spaces in the pathname or filename (although there isn't in this example).

By doing this, you can run your program no matter WHERE your program is locates AND no matter what YOUR current location is (ie, what folder you're currently in).

The commands:


On it's own will tell you where YOU current are and,

   DIR /A-D /S C:\program.exe

Will tell you where your program is.
If you add your program's path to the system path setting then you might want to add it to the front like this:

PATH=C:\MyPrograms;C:\Program Files;C:\WINDOWS\system32;C:\WINDOWS

Instead of:

PATH=C:\Program Files;C:\WINDOWS\system32;C:\WINDOWS;C:\MyPrograms

Because the nearer the front of the path setting, the faster the system is able to find your program (and hence, run it).


That's awesome! Thanks all!