How to invoke a program in Windows from command prompt?

21

2

I've added Notepad2 path to Path

enter image description here

And when I do notepad2 somefile.js - it says it's not recognized as an internal or external command.

I tried notepad2.exe - still doesn't work. What else I should do to be able to do what I can do with notepad? i.e. notepad somefile.txt - boom, opens it.

Marina Dunst

Posted 2017-02-13T18:37:23.003

Reputation: 627

29Is that colour scheme deliberate? :) – Lightness Races with Monica – 2017-02-13T19:07:13.207

7@LightnessRacesinOrbit Yes, it is. Custom made. Win 7 Pro but it's an older PC so I switched to Windows Classic theme to make it a bit faster. No sunlight. – Marina Dunst – 2017-02-13T19:26:44.013

1

An app I can't live without any more, when editing PATH and other environment variables: https://www.rapidee.com/

– Ajasja – 2017-02-14T08:58:32.597

Answers

56

You need to add the path of the folder containing notepad2.exe not the full path to the actual exe. So use:

C:\Program Files\Notepad2\

NOTE: Changes you make to your PATH (or any other Environment Variable) do not take effect in programs that are already running. The easiest way to make sure that your changes take effect for all programs is to log out and then back in again (or restart the computer, if you also want Windows System Services to see the change). However, if you just need to use the changes in the Command Prompt, it is enough to close the cmd window and reopen it.

heavyd

Posted 2017-02-13T18:37:23.003

Reputation: 54 755

15Changes to your environment variables typically require a reload, so log out/log in should be sufficient, but a restart would do the trick as well. – heavyd – 2017-02-13T18:45:56.413

3Yay! It works! Victory for me, victory for everyone! Thanks! – Marina Dunst – 2017-02-13T18:49:13.800

1@MarinaDunst You can also restart explorer by opening the task monitor, killing all explorer.exe instances and then starting explorer.exe in File/Run new task. This will reload the environment variables for explorer, which will pass it along to all the new programs you start from it. – isanae – 2017-02-13T23:05:21.693

8When running from command line, you don't have to restart, log out, or kill explorer, you just need to kill all instances of CMD. And, actually, I'm think that any new instance will work, so you don't have to kill things that aren't related. – David – 2017-02-14T06:36:36.817

1@David Environmental variables are inherited from the launching process by default - so unless that's disabled (as in e.g. the run dialog IIRC), you need to restart the launcher as well. In most cases, that's explorer (start menu, desktop, "My Computer", anything that uses the shell, really). That's why relogging or restarting helps - you reload the shell, which reads the stored environmental variables. You don't have to kill all instances of CMD - only the ones where you want to use that variable. – Luaan – 2017-02-14T08:42:17.237

@Luaan False, all processes which implement WM_SETTING­CHANGED will refresh their environment variables. Among these processes is explorer.exe, which is why a logoff/logon is not necessary. Just starting a new cmd instance.

– Sebazzz – 2017-02-15T09:41:50.453

@Sebazzz You're right. Explorer is one of the very few who do that. I don't really use Explorer all that much :) I do wonder if some shell extensions might interfere with that, though, since I quite clearly remember cases where explorer had to be restarted. Or maybe it was just that the application changing the environmental variables wrote them to registry instead of changing the variables (through the API), so WM_SETTINGCHANGED wasn't dispatched. – Luaan – 2017-02-15T12:38:10.523

5

Depending on what you are doing, it is also possible to use the "App Paths" registry key.

This is how you are able to launch a number of applications, e.g. Chrome, Firefox, notepad++.exe, etc.., without them being in your "PATH".

Plus, it's best to keep the PATH variables as clean as possible, it will save a number of unnecessary files searches when the Search path is used. The order of the values in the path should also be considered for this reason.

HelpingHand

Posted 2017-02-13T18:37:23.003

Reputation: 1 435

2

To add to EMK's answer, if a program has been added to App Paths, it can be started with the start command.

– Random832 – 2017-02-14T04:03:53.847