How is it that I can run explorer.exe from any directory in the command prompt? [duplicate]
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.