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?

link|improve this question

62% accept rate
What are you really trying to accomplish? If you want to be able to easily open files with notepad++, the installer of notepad++ has a context menu option that you can right click and open a file with. – Nathan Adams Jan 3 '11 at 18:15
1  
@Nathan: I cannot see how your comment relates to the question. – paradroid Jan 3 '11 at 18:29
@paradroid: He means that adding notepad++ to the path is not required for using it. – harrymc Jan 3 '11 at 21:23
@harrymc: Well, that goes for any Windows program. The OP only used Notepad++ as an example. It seems pretty clear to me that he wants to execute .exe programs in %programfiles% easily in CMD. – paradroid Jan 3 '11 at 21:51
feedback

3 Answers

up vote 5 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.

link|improve this answer
Hi! This is a great idea (+1), I can now execute notepad++ "text.txt" for example but it doesn't seem to work with more than one command line arguments? – Louis Rhys Jan 4 '11 at 2:41
@Louis: I edited my answer. Ask if you need any further help. – paradroid Jan 4 '11 at 3:06
For notepad++ switches go before the filename. Thanks for your reply. – Louis Rhys Jan 4 '11 at 4:46
I don't think I'm going to need to use the switches soon (and if I do I can use the complete fullpath), but I think it will be very nice for the sake of other readers and completeness of the answer, if you also include how to do the if and if not, (unless it's too complicated to explain) – Louis Rhys Jan 4 '11 at 4:48
But why a batch file? Just put a shortcut to it in a folder that is in the path (a dedicated folder though, not in \Windows…). – Synetech May 25 '11 at 1:47
show 8 more comments
feedback

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%

References:

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

link|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
@Synetech: No, it doesn't. You could use bangs when using SETLOCAL ENABLEDELAYEDEXPANSION when you do not want percents expanded in a batch file though. – paradroid May 25 '11 at 3:24
Well something does, maybe setenv or something (though I’m pretty sure it was a version of setx); I’ll check my drive. Ah, I thought so; it was indeed an older version of SETX. – Synetech May 25 '11 at 3:43
show 2 more comments
feedback

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.

link|improve this answer
It would be nice to know why the under-vote. If I am wrong, then correct me. Otherwise don't down-vote, please. – harrymc Jan 3 '11 at 21:21
I didn't downvote you, but I think the downvote is because you're not offering a solution. The purpose of this question is that I want to know how to execute .exe programs like notepad++ easily in cmd, like paradroid said. (without having to refer to the fullpath) – Louis Rhys Jan 4 '11 at 2:07
@Louis Rhys: Well, as far as I see I do correct a misconception and offer a solution, as did Nathan Adams in his comment. Batch was not mentioned in the question. – harrymc Jan 4 '11 at 6:16
feedback

Your Answer

 
or
required, but never shown

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