How do I run a .exe file from the command prompt?

For example, if the .exe file is located at C:\file.exe, how do I run this file when the prompt is currently in another location like D:\?

link|improve this question
feedback

migrated from stackoverflow.com Dec 2 '09 at 1:23

This question came from our site for professional and enthusiast programmers.

5 Answers

You can either run it by using the explicit path:

c:\file.exe

or add its location to the path (I always have a c:\bin directory to hold my little snippets - not really a kosher location for multiple-user Windows, but none of my Windows installs are multiple-user):

copy c:\file.exe c:\bin  :: put it in a better directory.
path %path%;c:\bin       :: if not already in the path.
file                     :: run it (unless there is another 'file' in path).

Note that, with that second solution, you should be setting up your path so that it's available whenever you start up (in autoexec.bat if you're really using DOS or from the Control Panel -> System -> Environment window if you're using Windows).

And, do note that, if you use the control panel solution, that doesn't affect currently open command windows - you'll need to shut them down and re-open to pick up the new environment variable.

link|improve this answer
but its not working – maxy Dec 1 '09 at 12:12
1  
If you have spaces in file name or in a folder that contains that exe file, then add quotes: "c:\file.exe" – True Soft Dec 1 '09 at 12:16
what happens when you try either of the two ways? – malach Dec 1 '09 at 12:16
ya..its working..can i pass this cmd from program – maxy Dec 1 '09 at 12:21
1  
That's really a different question but you should look into system() for standard C, or (under Windows) something like CreateProcess(). – paxdiablo Dec 1 '09 at 12:27
show 3 more comments
feedback

if you are on your D: drive you still able to type " c:\file.exe"

link|improve this answer
feedback

To switch drives, just type C: and push enter. To change directories, type cd somedirectory.

Let's say I am at D:\Brad and I want to run C:\Windows\notepad.exe. You could either just type it's name explicitly like others have suggested, or you could do this:

C:
cd \Windows
notepad
link|improve this answer
feedback

You should add the c:\ path into your Windows system PATH so whatever drive you are in and when you execute the file.exe windows will look at your defined path and run your program there.

TO do this go to Windows -My computer -click right for Properties - Advanced Button - Environment Variables - at the buttom of the windows you will see the PATH - Edit it add ;c:\ and save This should work - I think it will need a reboot

link|improve this answer
feedback

The best way to run an EXE file that you don't known its full name is:

Assuming your file name is Installer_4756873653.exe but you don't know the full name after the Installer_ and the location of the file is C:\

cd C:\
dir Installer_*.* /b > FileToRun.bat
FileToRun.bat
link|improve this answer
1  
Why not just type "Installer" and then hit tab? – DanH Mar 1 at 16:31
feedback

Your Answer

 
or
required, but never shown