Where does windows start search the executable? [duplicate] - windows

This question already has answers here:
Where is "START" searching for executables?
(2 answers)
Closed 2 years ago.
I can start notepad++ with the start notepad++ successfully. But using notepad++ directly does not work.
the file Notepad++.exe in directry C:\Program Files\Notepad++
the shortcut of Notepad++.exe in directory C:\ProgramData\Microsoft\Windows\Start Menu\Programs
the %Path% shown below not contains C:\ProgramData\Microsoft\Windows\Start Menu\Programs and C:\Program Files\Notepad++
Where does start fetch the executable from?
C:\Program Files\Huawei\jdk1.8.0_222\bin;C:\Program Files\Huawei\jdk1.8.0_222\jre\bin;C:\Program Files (x86)\NetSarang\Xshell 6\;C:\windows;C:\windows\system32;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0;C:\Windows;C:\Windows\system32;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\windows\System32\WindowsPowerShell\v1.0\;C:\windows\System32\OpenSSH\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Git\cmd;C:\Program Files\apache-maven-3.3.9\bin;C:\Program Files\Git\bin;C:\Users\w30004809\Program Files\mysql-8.0.20-winx64\bin;C:\Program Files\QuickStart;C:\Users\w30004809\AppData\Local\Microsoft\WindowsApps;

Without start, CMD will only run files that it finds with a PATH search. In this case, it first tries to run the file via CreateProcessW and falls back on ShellExecuteExW. On the other hand, the internal start command always tries ShellExecuteExW even if it can't find a file. This allows using the shell API to find the executable via one of the system or user "App Paths" keys (e.g. start notepad++ when "notepad++.exe" is not found in PATH). It also allows opening a directory in a file explorer (e.g. start D:\); accessing the shell namespace (e.g. start shell:appdata); and using other registered protocol handlers such as HTTP (e.g. start http://www.stackoverflow.com).

There are different things here: when you type the name of an application, Windows checks the %PATH% environment variable, in order to start it. Please edit your question and add the value of that variable.
Next, why do you type start <application>? This means that you want to open a next command Window and launch that application in there, which makes no sense if the application is a Windows executable. Just type "Notepad++".
In top of that, please also check the location of the Notepad++.exe file, we might check if it's located in the %PATH% environment variable or not.

Related

System cannot find path even though it exists in paths

Working on a batch file that calls another batch file.
K:\Market Risk>call "K:\Market Risk\activate.bat"
The system cannot find the path specified.
So I set the path at the beginning of my batch file and made sure it was there:
SET PATH=%PATH%;K:\Market Risk\
K:\Market Risk>echo %PATH%
C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;
C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;
C:\WINDOWS\System32\OpenSSH\;C:\Program Files (x86)\Shoreline Communications\
ShoreWare Client\;C:\Program Files\dotnet\;C:\Program Files (x86)\Microsoft SQL Server
\150\DTS\Binn\;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\
WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files (x86)\
Shoreline Communications\ShoreWare Client\;C:\Program Files (x86)\Common Files\Oracle\
Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;
C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;
C:\Program Files (x86)\Shoreline Communications\ShoreWare Client\;
C:\Users\Kyle.Dixon\AppData\Local\Microsoft\WindowsApps;C:\Users\Kyle.Dixon\AppData\Local\
Programs\Git\cmd;C:\Users\Kyle.Dixon\AppData\Local\atom\bin;C:\Users\Kyle.Dixon\Documents\
R\R-3.5.2\bin\R.exe;C:\Users\Kyle.Dixon\Documents\R\R-3.5.2\bin;C:\Users\Kyle.Dixon\
AppData\Roaming\MarketView\MarketView ExcelTools\;K:\Market Risk\
However, I'm still getting the same error:
K:\Market Risk>call "K:\Market Risk\activate.bat"
The system cannot find the path specified.
Has anyone had this issue before?
I recommend reading What is the reason for "X is not recognized as an internal or external command, operable program or batch file"? It should help to understand how the environment variable PATH is managed by Windows. It is unfortunately not really good managed by Windows which cause lots of problems because of no command is available to safely add/remove a folder path to system or user PATH. The results of missing such a command or executable written by Microsoft to safely update PATH with applying all necessary error checks are lots of not good coded scripts which quite often corrupt system and user PATH stored in Windows registry on trying to update them.
My recommendation is opening Windows Control Panel - System and Security (on View by: Category selected) - System - Advanced System Settings - Environment Variables as administrator and cleaning up both Path environment variables, the user Path (upper pane) and the system Path (lower pane). The window Environment Variables can be opened also by clicking on Windows Start button, typing on keyboard environment and Windows suggests in the menu Edit environment variables for your account and Edit the system environment variables in the language of Windows. Click on one of the two suggested items and if necessary depending on Windows version next on button Environment Variables.
The system Path should start always with following default Windows folder paths:
%SystemRoot%\System32
%SystemRoot%
%SystemRoot%\System32\Wbem
%SystemRoot%\System32\WindowsPowerShell\v1.0\
%SystemRoot%\System32\OpenSSH\
The system Path was badly updated once in the past if it does not start anymore with these folder paths exactly as written here. (The last folder path is available only on Windows 10 since version 1809 and of course Windows 11.) C:\WINDOWS stored in Windows registry and displayed on editing the system Path instead of %SystemRoot% is an indication that an installer executable or script has not good updated system Path because of replacing original folder paths with referencing environment variable SystemRoot by the expanded version. This does not really matter for these folder paths, but could have been harmful for other folder paths.
No folder path should exist more than once in one of the two Path environment variables.
Remove all duplicates in user Path as well as in system Path.
Your two Path environment variables contain three times:
C:\Program Files (x86)\Common Files\Oracle\Java\javapath
C:\Program Files (x86)\Shoreline Communications\ShoreWare Client\
C:\WINDOWS
C:\WINDOWS\system32
C:\WINDOWS\System32\OpenSSH\
C:\WINDOWS\System32\Wbem
C:\WINDOWS\System32\WindowsPowerShell\v1.0\
A folder path existing already in system Path should not exist a second time in user Path and of course also not once more in system Path.
A folder path can be listed without or with a backlash in Path. I prefer folder paths without backslash at end in Path as this causes less troubles on updating Path in future on using command reg by a batch script.
Environment variable Path should contain only folder paths and not fully qualified file names.
So C:\Users\Kyle.Dixon\Documents\R\R-3.5.2\bin\R.exe is completely nonsense in Path.
After cleanup of both Path environment variables the folder paths in system Path should be something like:
%SystemRoot%\system32
%SystemRoot%
%SystemRoot%\System32\Wbem
%SystemRoot%\System32\WindowsPowerShell\v1.0\
%SystemRoot%\System32\OpenSSH\
%CommonProgramFiles(x86)%\Oracle\Java\javapath
%ProgramFiles(x86)%\Microsoft SQL Server\150\DTS\Binn
%ProgramFiles(x86)%\Shoreline Communications\ShoreWare Client
C:\Program Files\dotnet
For the last path it is better to keep C:\Program Files and do not use %ProgramFiles%, except there is C:\Program Files\dotnet and C:\Program Files (x86)\dotnet which I don't know as I don't have such a directory on my Windows computer. For the reason see the Microsoft documentation page WOW64 Implementation Details.
The user Path should be finally something like:
%LocalAppData%\atom\bin
%LocalAppData%\Microsoft\WindowsApps
%LocalAppData%\Programs\Git\cmd
%AppData%\MarketView\MarketView ExcelTools
%UserProfile%\Documents\R\R-3.5.2\bin
There is not much written about environment in which the two batch files are executed. So most written below is pure speculative.
I suppose that drive K: is not a drive on a local hard disk, but a network drive. So it is possible that the network resource mapped to drive K: is currently not available either because of network resource not mapped to drive letter K: or there is network connection issue or a network resource permission issue.
Windows remaps a network resource to a drive letter as once done by the user only on logon of the user because of network drive mappings are user account related stored by Windows in Windows registry. So if the batch file is executed as scheduled task with using a different account or also on user not logged in, the drive K: does indeed not exist. The scheduled task executing the batch file must be configured to use the account which has the necessary permissions to access all network resources and local directories/files which are accessed by the batch file. And it is additionally necessary to access files and folders on a network resource with their UNC paths instead of using drive letter K: of network drive not existing on execution of the batch file in this environment.
See also: What must be taken into account on executing a batch file as scheduled task?
But possible is also that the error message
The system cannot find the path specified.
is not output by cmd.exe on processing the batch file containing the command line
call "K:\Market Risk\activate.bat"
but on a command line executed on processing the batch file K:\Market Risk\activate.bat.
Therefore I suggest to remove from both batch files #echo off at top or change it to #echo on and run the main batch file from within a command prompt window, see debugging a batch file. Then it should be 100% clear which command line in which batch file is responsible for this error message.

Unable to remove cygwin from PATH environment variable

I recently had to reinstall Cygwin and in doing so, I have ran into a problem with some application because Cygwin seems to be appended to my PATH environment variable. I have tried to remove this by following these instructions https://www.java.com/en/download/help/path.xml but something strange happens. If I look at the value of Path under 'Environment Variables', Cygwin is not there; however if I type PATH in cmd.exe, I see Cygwin gets appended at the end of the PATH. Can you please help me to know to remove Cygwin from the PATH?
As an example, this is what I see in the Environmental Variables window Path value:
Path=C:\Program Files (x86)\Intel\iCLS Client\;C:\Program
Files\Intel\iCLS
Client\;c:\Oracle\11g_R2_x64\Administrator\11.2.0\client_1\bin;C:\ProgramData\Oracle\Java\javapath;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;%systemroot%\System32\WindowsPowerShell\v1.0\;C:\Program
Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files
(x86)\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\IPT;%systemroot%\System32\WindowsPowerShell\v1.0\;C:\Apps\Anaconda3;C:\Apps\Anaconda3\Scripts;C:\Apps\Anaconda3\Library\bin
And this is what I see in cdm.exe:
PATH PATH=C:\Program Files (x86)\Intel\iCLS
Client\;C:\Program Files\Intel\iCLS Clien
t\;c:\Oracle\11g_R2_x64\Administrator\11.2.0\client_1\bin;C:\ProgramData\Oracle\
Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS
\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:
\Program Files\Intel\Intel(R) Management Engine
Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine
Components\DAL;C:\Program Files\Intel\Int el(R) Management Engine
Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Man agement
Engine
Components\IPT;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\App
s\Anaconda3;C:\Apps\Anaconda3\Scripts;C:\Apps\Anaconda3\Library\bin;C:\blp\DAPI;
C:\blp\DAPI\DDE;C:\Apps\cygwin64\bin
As you can see, I have Cygwin in the second case, whereas I don't have it on the first case.
UPDATE:
Thanks to Patrick for his answer below. Just to complement, in Windows you should be able to edit both the user and system environment variables from the Control Panel as in this screenshot:
There are two PATH variables in Windows. Both are available on that page for environment variables. One is in the top pane (User variables) and the other is in the second pane (System variables). They are both called PATH, but they are separate and distinct entities. When you launch cmd.exe, the PATH variable you end up with is the result of combining those two variables. To fix the problem you are seeing here, return to the Environment Variables pane and check both versions (User and System). Based on your PATH variables above, I suspect the User PATH will contain the following three entries:
C:\blp\DAPI;
C:\blp\DAPI\DDE;
C:\Apps\cygwin64\bin
That's the only functional difference in your cmd.exe PATH and the other on after variables like SYSTEMROOT are expanded. You should be able to delete the Cygwin directory there.
My problem was different, but still led me here, so hopefully someone else might benefit from this.
In my case, C:\cygwin64\bin was NOT present in either the user variables PATH or the System variables PATH. However, whenever I ran python it was using the executable stored in C:\cygwin64\bin instead of the location I had python installed to.
(This was confirmed by running Get-Command python | Select-Object -ExpandProperty Definition in PowerShell).
It turned out my problem was that for whatever reason my System variables Path also contained C. Yes, just C. Removing this effectively removed C:\cygwin64\bin from my Path (and anything else the root C:\ directory).
So if you're having an issue like this where something that's NOT in your path is behaving as if it is, maybe check if that item's parent directory has been added.

Duplicates in windows environment path

For some reason I do not know, my echo %path% has many duplicates of C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\. As far as I know, long %path% is bad because it slows the searching process. Is it safe to remove these duplicates?
I also noticed that there are two version of path variable: one for user variables and one for system variables. If I type echo %path% in command prompt as normal user, it will show the concatenation of these two version (system version comes first). If I am to remove the duplicates, from which version should I remove?
(bold one is system version)
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 (x86)\Intel\OpenCL SDK\3.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x64;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;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x64;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;C:\MinGW\bin;C:\Python27;C:\Users\jie\AppData\Local\Microsoft\WindowsApps
On Microsoft Technet (Scriptcenter) there used to be a small PowerShellScript which checks against duplicate paths: How to check for duplicate paths in PATH environment variable
(It's gone now, at the original location, but archive.org has a copy.)
Should be run in a PowerShell environment with admin rights. I do this after every uninstall of any software (Windows 10 x64).
The paths you mention are system paths. They should stay in the PATH variable in the system scope. You can remove the duplicates in the PATH variable of the user scope, but you should reboot and check, if every application is still working (not because you deleted a duplicate, but to make sure you didn't delete something wrong by mistake). As usual, backup your PATH variables somewhere, before you start.
Duplicates inside each scope can always be safely removed. The list is split at every semicolon and each resulting path in the list is searched. If there are duplicates, the same search simply executes twice in the worst case. In the best case, the system might recognize the duplicates (I'm not sure if this happens), but this would mean additional effort for recognizing. So your statement on slowing down is correct in any case.
The reason for you duplicates (if it wasn't you at least) might probably be some application you installed somewhen, which edited the PATH variable improperly.
I was still wondering why some processes have a duplicate part in the PATH environment variable.
Some investigating, the problem occurs by processes started by explorer.exe. It does not occur for processes which were not initially a child process (or 'child process of child process') of explorer.exe.
I think, the user part of the Windows PATH environment variable is influencend by :
The two registry entries:
HKCU\Environment\Path
HKCU\Environment\1\Path
The process explorer.exe (which is runnng in the user context) loads both entries for the PATH environment variable.
I deleted for the test HKCU\Environment\Path when HKCU\Environment\1\Path exists. The duplicate part of the PATH environment variable no longer exists.
Deleting or modifying this registry key should be done very carefully. Probably you ran in other unexpected problems, because the Windows Path environment variable affects all new processes started by the current user.
Note
Microsoft encourages the usage of App Paths, because the more entries the path environment variable Path has, the more time Windows is spending for searching for specified files. With App Paths you can specify per executable name the folders where the executable should search.
More information: Microsoft Docs about App Paths.

Problems with javac

[EDIT][EDIT2][EDIT3]I need help as I am starting on JSP. My goal is to run the java compiler in the windows cmd and I have encounter this error:
'javac' is not recognised as an internal or external command,operable program or batch file.
What I have done to debug this problem so far:(Not in order)
Check the path name
redownload the sdk
rerun the cmd after changing to the correct path name
Edited the environment variable to include the sdk
And yet all fails what have I not done correctly.
My pathname is It still doesn't work. I am following instructions from here http://www3.ntu.edu.sg/home/ehchua/programming/howto/tomcat_howto.html
This is my pathname: C:\Program Files (x86)\Java\jdk1.8.0_60\bin
For ricovox: This is the complete cmd output for path
C:\Users\Zi>path
PATH=C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\ProgramData\Oracl
e\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 (x86)\Intel\OpenCL SDK\2.0\bi
n\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Intel
\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Manag
ement Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Eng
ine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Compo
nents\IPT;C:\Program Files (x86)\Citrix\system32\;C:\Program Files (x86)\Windows
Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110
\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;C:\Prog
ram Files\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQ
L Server\110\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL S
erver\110\DTS\Binn\;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Skyp
e\Phone\
Edit System Variable
Variable name: JAVA_HOME
Variable value: C:\Program Files (x86)\Java\jdk1.8.0_60\bin
So first, please verify that you have set the JAVA_HOME environment variable. Here are the instructions to set it:
Open the Windows Control Panel Go to System ⇒ Advanced system
settings
Switch to "Advanced" tab ⇒ Environment Variables
In the System Variables box, (not User variables), click "New" (or
"Edit" for modification)
In "Variable Name", enter "JAVA_HOME"
In "Variable Value", enter your JDK installed directory: C:\Program Files (x86)\Java\jdk1.8.0_60\bin.
Click OK and close that window.
Now, open up a NEW windows command prompt (cmd.exe) and type the following:
set JAVA_HOME
You should see something like this:
JAVA_HOME=C:\Program Files (x86)\Java\jdk1.8.0_60\bin
Setting JAVA_HOME may be required for Tomcat/JSP, but just doing that will not necessarily allow you to run javac from the command-line. If you want to be able to do that, you also have to add the java bin folder to your PATH environment variable.
To do that, follow the same instructions as above, with some minor changes as shown below:
Open the Windows Control Panel Go to System ⇒ Advanced system
settings
Switch to "Advanced" tab ⇒ Environment Variables
In the System Variables box, (not User variables), find the Path variable in the list and click on it. Then click the "Edit" button.
Copy the entire value in the "Variable Value" field and save it somewhere (just in case you make a mistake and need to restore it later.)
Press the END key to go to the end of the current Path value, then enter a semicolon (;) followed by your java directory. For example:
C:\Windows;C:\Windows\system32;...SomeOtherFolders...;C:\Program Files (x86)\Java\jdk1.8.0_60\bin
Click OK and close that window.
Now, open up a NEW windows command prompt (cmd.exe) and type the following:
PATH
You should see a list of paths and the list should contain your java directory (it may or may not be the last path in the list, depending on whether you have a Path variable defined in the User variables section.)
Once you have the java bin folder in your PATH, you should be able to run javac from the command-line.
You can test this by opening a command prompt and typing javac -version You should see the output javac 1.8.0_60
You should also try %JAVA_HOME%\javac -version just to make sure your JAVA_HOME variable is correct.
I hope that helps.

Detect commandline application from CMD without messing with PATH variable or System32/SysWow64 dir

Scenario
I would like to install an x86 CommandLine application on a folder outside C:\Windows\System32 or C:\Windows\Syswow64 and still be able to access my app under CMD without adding my application's path inside the PATH environment variable.
Question
Is this possible to do? Maybe touching a needed registry keys?
Note: I know how to add my application into PATH variable/regvalue or how to access my application from CMD putting the required .exe in the System32/SysWow64 folder. This question is only to learn alternatives, it's not to solve issues with PATH or System dirs.
Code
I've tried this suggested approach from a comment of #Sertac Akyuz in this answer, I have stored MyApp.exe on C:\ root directory, but I can't detect the application just putting MyApp.exe under the CMD.
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\App Paths\MyApp.exe]
#="C:\\MyApp.exe"
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths\MyApp.exe]
#="C:\\MyApp.exe"
[HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\App Paths\MyApp.exe]
#="C:\\MyApp.exe"
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App Paths\MyApp.exe]
#="C:\\MyApp.exe"
App Paths registry settings - used by Windows Explorer, to locate programs when you type program name in "Run..." box, and so on. These settings are not affecting cmd.exe behavior.
The only way to set up cmd.exe paths for searching applications is changing PATH environment variable. You can start cmd.exe from your own .bat/.cmd where you set up all required variables for current session, without changing it globally.

Resources