This question already has an answer here:

How is it that I can run explorer from command prompt regardless of which directory I'm in?

How can I mimic this with my own exe? Is it merely the fact that this exe exists in the Windows dir?

marked as duplicate by DavidPostill windows Jun 1 '17 at 8:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 4
    -1 very poorly phrased. Re your title "How can I run explorer.exe from any dir in command prompt? " <-- My main point to you You mean "Why is it that I can run...". or "How is it that I can run". To say "How can I run" suggests that you might mean that you can't and you want to know how. You could have worded the title much better. And it's not just explorer. calc.exe too, or notepad. Secondary point - You should say directory, 'dir' is a command, especially in the context of the command prompt. Much clearer to say 'directory'. – barlop May 31 '17 at 16:52
  • 30
    @barlop Wow, you couldn't have been harsher on a new user if you tried, and for little cause as you could have edited without commenting.. – cat May 31 '17 at 18:34
  • 1
    @cat it wouldn't be the first time he has ever asked anybody a question, so being the first time has has asked on this particular site is far from any kind of excuse, and my prompt might help him think better when he asks a question. – barlop May 31 '17 at 18:55
  • 27
    @barlop Yeah, but you could have put it nicer: "What you're really asking, jaymee, is 'How can I run my own exe from command prompt, regardless of which directory I'm in'? The way you phrased it is misleading..." – Shawn V. Wilson May 31 '17 at 19:12
  • 6
    @barlop Your grammar "corrections" are completely unnecessary and the way you presented them appeared very hostile. It's ridiculous to have to remind a 13.5k-rep user of six years' standing to be nice. – David Richerby Jun 1 '17 at 0:00

How is it possible for me to run explorer from command prompt regardless of which directory I'm in?

This is because C:\Windows is contained in the list of paths contained within user's system environment variables. I am specifically talking about the PATH variable.

How can I mimic this with my own exe?

Add the location of the executable to the system variable.

Is it merely the fact that this exe exists in the Windows directory?

The Windows directory is contained within the list of paths contained in the PATH system environment variable.

How is it that I can run explorer from command prompt regardless of which directory I'm in?

You can run explorer from any directory because the directory containing explorer.exe has been added to the computer's PATH environment variable.

How can I mimic this with my own exe?

Yes. You just need to add the exe's directory to your system's PATH. To do this follow these steps:

1. Click on "Computer" in windows explorer
2. Click "System Properties"
3. Click "Change settings"
4. Click "Advanced"
5. Click "Environment Variables"
6. Select the PATH variable and click "Edit"
7. Move your cursor to the end of the variable value box.  Add a 
   semicolon and the path for the directory that your executable resides in.

Is it merely the fact that this exe exists in the Windows dir?

It is because the exe exists in the Windows dir AND because the Windows dir exists in your computers PATH environment variable.

Normally explorer.exe would be on your path, so it should already be available within any command prompt shell that you open. If you open a command prompt and enter path, you should see something like the following:

PATH=C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;

C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem; C:\Windows\System32\WindowsPowerShell\v1.0\; C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT; C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT

The key component is C:\Windows. This is the directory that holds the explorer.exe executable. If it is not in your path, something is wrong, it should always be there in a normal Windows installation. You can manually add it to your path through the following steps:

  • Select Start, select Control Panel. double click System, and select the Advanced tab.
  • Click Environment Variables. …
  • In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. …

After you have updated your path that way, then explorer should be available in any command prompt window. Just open a new command prompt and enter explorer. It should then bring up an Explorer instance for you.

The above steps are provided as an example whereby you can see how the folder that contains the explorer executable is on your path. Your real question is about how to make an exe file that you have created behave the same way as explorer. You would accomplish this by following the steps to edit your path environment variable as just described, except that you would insert into your path the folder that contains your exe file. Then it should be available in any command prompt that you subsequently open.

You need to make sure that the exe is in a folder that's on the PATH environment variable like this

  • 5
    Your link is POSIX-centered. Colon is not a paths separator in Windows' PATH. – Ruslan May 31 '17 at 16:09
  • 6
    also, copy relevant part to the answer itself - answer should be usable even when link becomes broken in the future (as they all do at some time) – Matija Nalis May 31 '17 at 19:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.