Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

For example, I want to add notepad++ to my PATH, however the directory also contains uninstall.exe and several other files/executables and I don't want them to "pollute" my path. Can I just add the one notepad++.exe?

share|improve this question

5 Answers 5

up vote 13 down vote accepted

You can add a batch script to a directory that is in your path, that looks something like this:

@echo off

:: Notepad++ execution

if [%1]==[-h] goto :HELP
if [%1]==[--help] goto :HELP
if [%1]==[/?] goto :HELP
goto :START

:START
start "" /i "%ProgramFiles(x86)%\notepad++\notepad++.exe" %*
goto :EOF

:HELP
echo -------------------------------
echo Notepad++ Command Argument Help
echo -------------------------------
echo Usage :
echo.
echo notepad++ [--help] [-multiInst] [-noPlugins] [-lLanguage] [-nLineNumber] [-cColumnNumber] [-xPos] [-yPos] [-nosession] [-notabbar] [-ro] [-systemtray] [-loadingTime] [fullFilePathName]
echo.
echo     --help : This help message
echo     -multiInst : Launch another Notepad++ instance
echo     -noPlugins : Launch Notepad++ without loading any plugin
echo     -l : Launch Notepad++ by applying indicated language to the file to open
echo     -n : Launch Notepad++ by scrolling indicated line on the file to open
echo     -c : Launch Notepad++ on scrolling indicated column on the file to open
echo     -x : Launch Notepad++ by indicating its left side position on the screen
echo     -y : Launch Notepad++ by indicating its top position on the screen
echo     -nosession : Launch Notepad++ without any session
echo     -notabbar : Launch Notepad++ without tabbar
echo     -ro : Launch Notepad++ and make the file to open read only
echo     -systemtray : Launch Notepad++ directly in system tray
echo     -loadingTime : Display Notepad++ loading time
echo     -alwaysOnTop : Make Notepad++ always on top
echo     fullFilePathName : file name to open (absolute or relative path name)
echo.
goto :EOF

:EOF

You can name it notepad++.cmd. The help section allows you to easily get information on the switches.

I put all such scripts and command line programs in a directory which is added to %PATH%: C:\Users\Public\Command\ ...and that directory is synced to all computers and virtual machines.

share|improve this answer

Drag a shortcut to notepad++.exe to C:\Windows\System32.


Alternatively, as suggested by @Synetech inc., you could place your shortcuts in a separate directory (e.g. C:\Shortcuts), and then add that directory to %PATH%:

setx PATH "C:\Shortcuts;%PATH%"

As some of the comments indicate, this only works from the Run dialog. In order to get the shortcuts to launch from a command prompt you need to add the shortcut extension (.lnk) to your PATHEXT environment variable.

setx PATHEXT .LNK;%pathext%

References:

How can I start applications easily with the Run dialog box?

share|improve this answer
1  
This is the preferred solution (as opposed to a batch file); create a shortcut to it in a (different) directory in the path—don’t pollute Windows’ directories! I have a folder specifically for this purpose called Shortcuts. –  Synetech May 25 '11 at 1:46
1  
That's the wrong syntax for setx. You do not use an equals sign, and IIRC, you need to enclose the whole path in quotes, if the current %PATH% has spaces in it (which it will). –  paradroid May 25 '11 at 2:51
    
And doesn’t SETX use tildes for variables instead of percents to avoid expanding them? I know that some env-var setting tool does… –  Synetech May 25 '11 at 3:01
1  
This doesn't work. By default (I'm dragging git.exe), "git - Shortcut", renaming this to combinations of "git.exe", "git", "git.cmd" etc. has no effect. It won't acknowledge the shortcut. –  Matt Joiner Jul 3 '12 at 17:58
1  
This only works when invoking from the Run As dialog, it didn't work from the command prompt. –  Matt Joiner Jul 3 '12 at 18:41

The App Paths registry key does exactly this: set the path to notepad++.exe to "\program files\..." and you'll be able to launch it from Start-Run, cmd, ... just like any executable from a directory in %PATH%.

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths

Reference: http://stackoverflow.com/questions/4822400/register-an-exe-so-you-can-run-it-from-any-command-line-in-windows

share|improve this answer

Create a batch file with contents like the following:

@"C:\Program Files\Git\bin\git.exe" %*

This should be saved as a .bat file, such as git.bat in a directory that's in your PATH.

@ suppresses echoing the command to the invoking shell. The quotations "" prevent white space being interpreted as argument delimiters. %* pastes any arguments to the batch file, to the quoted executable instead.

You can now invoke the executable using the part of the batch file name before .bat. In my case, git.

References:

share|improve this answer
    
For many programs that will hang up CMD until you close it. You need to use start to avoid that, as shown in my answer. –  paradroid Jul 3 '12 at 19:15
    
@paradroid: Thanks, but it's standard terminal behaviour to remain attached to the parent unless asked. The user should do start git rather than have it done for them. The batch script would act better if it execd into the requested process but this isn't possible on Windows: serverfault.com/questions/315077/…. I could prepend call but it would be pedantic and mostly pointless. –  Matt Joiner Jul 3 '12 at 20:46

AFAIK only folders are added to the path, not executables.
At least that's what is written in the documentation.

Unless the documentation is wrong, you will be adding to the path %programfiles%\notepad++\, so in effect it is "polluted" by uninstall.exe and other executables in this same folder.

The only solution would be to not include the notepad++ folder in the path, and refer to the executable by its full path-name.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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