1

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? cmd picture

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;
Peng Wang
  • 13
  • 3
  • 1
    BTW, you have five duplicate entries in your `%PATH%` value, which should be removed, `C:\windows`, `C:\windows\system32`, `C:\windows\System32\Wbem`, `C:\windows\System32\WindowsPowerShell\v1.0`, `C:\Windows\System32\WindowsPowerShell\v1.0` – Compo Jul 10 '20 at 11:07
  • For your System `%PATH%`, I would suggest the following entries, `C:\Windows`, `C:\Windows\system32`, `C:\Windows\System32\Wbem`, `C:\windows\System32\WindowsPowerShell\v1.0\ `, `C:\windows\System32\OpenSSH\ `, `C:\Program Files\Intel\Intel(R) Management Engine Components\DAL`, `C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL`, `C:\Program Files\Git\bin`, `C:\Program Files\Git\cmd`, `C:\Program Files\Huawei\jdk1.8.0_222\bin`, `C:\Program Files\Huawei\jdk1.8.0_222\jre\bin`, `C:\Program Files\apache-maven-3.3.9\bin`. – Compo Jul 10 '20 at 11:26
  • … and for the User `%PATH%` these, `C:\Users\w30004809\AppData\Local\Microsoft\WindowsApps`, `C:\Users\w30004809\Program Files\mysql-8.0.20-winx64\bin`, `C:\Program Files (x86)\NetSarang\Xshell 6\ `, `C:\Program Files\QuickStart`. – Compo Jul 10 '20 at 11:26

2 Answers2

1

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

Eryk Sun
  • 33,190
  • 5
  • 92
  • 111
  • One other difference as a consequence of what you wrote is that "start" also is able to execute lnk files. I assume that ist the reason of the different behaviour in the case of the person asking. – Andre Ruebel Jul 10 '20 at 12:22
  • @AndreRuebel, shell links (.lnk files) are regular files that can be executed without `start`. By default you have to include the .lnk extension in the name because ".LNK" isn't included in the default `PATHEXT` environment variable, but of course it can be added. It's a good way to aggregate a bunch of executables from various directories in a single directory that's added to `PATH`, but in this case you should make sure that the "start in" directory of the shell link is blank in order to inherit the working directory of the parent process. – Eryk Sun Jul 10 '20 at 12:32
  • @ErykSun,, does CMD not start with the current working directory? – lit Jul 10 '20 at 12:58
  • @lit, `CreateProcessW` and `ShellExecuteExW` allow setting the working directory of a child process. Normally CMD leaves it at the default that inherits the current directory, but `start` allows setting it explicitly via `/D`. Either way, implcit or explicit, if a shell link sets the "start in" directory, the shell API will use that directory instead of the directory that CMD passes in the `SHELLEXECUTEINFOW` record. So the "start in" field needs to be left empty if you want a child process to either implicitly inherit the working directory or to be able to set it explicitly with `start /D`. – Eryk Sun Jul 10 '20 at 13:46
0

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.

Dominique
  • 16,450
  • 15
  • 56
  • 112
  • because of convenience, if I want to open a application, just WIN+R, then type `start `. there is no need to leave keyboard and use mouse to find application on desktop – Peng Wang Jul 10 '20 at 09:06
  • @PengWang, `start` is a built-in command in the CMD shell, so it doesn't work from the Win+R run dialog. But the run dialog basically uses `ShellExecuteExW`, so running `notepad++` via Win+R will work as well, without having to add Notepad++ to `PATH`. It's using a "notepad++.exe" subkey of either the system or user "App Paths" key. – Eryk Sun Jul 10 '20 at 09:17
  • @ErykSun I think I kown. `start notepad++` use a "notepad++.exe" subkey of either the system or user "App Paths" key or %PATH% to locate executable. `notepad++` locates executable with %Path% – Peng Wang Jul 10 '20 at 09:46
  • @ErykSun It's clear for me now. – Peng Wang Jul 10 '20 at 10:04