We help IT Professionals succeed at work.

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

chenyuhao88
chenyuhao88 used Ask the Experts™
on
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!
Comment
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

Commented:
You first need to add your program to the system environment path.
Expert of the Quarter 2010
Expert of the Year 2010
Commented:
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.

e.g.

was: C:\windows;C:\windows\system23
to: C:\windows;C:\windows\system23;C:\program files\my\app
ee.PNG
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.
Commented:
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:

   program

You would enter the followinf (full) command instead:

   "c:\files\utilites\program"

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:

   CD

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.
Commented:
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).

Author

Commented:
That's awesome! Thanks all!