Finding out install location - could you try on cmd?
-
Hey guys! I’m trying to improve a script that depends on N++ in finding out installation location. It is currently uses
where notepad++, which only works in case N++ is in%path%. I want to add regedit query, for cases where it’s not in system path, but I don’t want to install/reinstall various versions (win32/win64), and I only have access to Win10 and Win11.So, could you, please, try running this command in the command prompt and share the output? It would help me out a lot. I’m especially interested in older versions of Windows, and Win32 version of N++
The command:
for /f "tokens=2 delims=REG_SZ" %i in ('reg query HKLM\SOFTWARE\Notepad++ ^| findstr /i /l /c:"Default"') do @echo %iHere’s what I get:
C:\>for /f "tokens=2 delims=REG_SZ" %i in ('reg query HKLM\SOFTWARE\Notepad++ ^| findstr /i /l /c:"Default"') do @echo %i 2> NUL C:\Program Files\Notepad++ C:\>Would appreciate any help from win32 N++ installation, and older versions of Windows. Thanks!
-
My systems are all Win10/Win11 as well, and I only install the 64bit version. However…
Based on what I could find in the installer section of the source code,
HKLM\SOFTWARE\Notepad++is the correct place to look.That’s the place used by the installer for both writing and reading
- https://github.com/notepad-plus-plus/notepad-plus-plus/blob/40adc3820140c5a52d134a7f7085e328776bec99/PowerEditor/installer/nsisInclude/tools.nsh#L182
- https://github.com/notepad-plus-plus/notepad-plus-plus/blob/40adc3820140c5a52d134a7f7085e328776bec99/PowerEditor/installer/nsisInclude/globalDef.nsh#L72
- https://github.com/notepad-plus-plus/notepad-plus-plus/blob/40adc3820140c5a52d134a7f7085e328776bec99/PowerEditor/installer/nppSetup.nsi#L203
And it’s what’s deleted by the uninstaller:
Looking at the blame for one of those writes that the installer does, it’s been using that same location in the registry for at least 8 years.
I think it’s a safe bet that if someone has used the installer, that
HKLM\SOFTWARE\Notepad++key will exist. -
@OpossumPetya said in Finding out install location - could you try on cmd?:
Hey guys! I’m trying to improve a script that depends on N++ in finding out installation location.
The
regeditquery will only work on “installed” Notepad++ installations. I only use the portable version. For me, the query obviously would (and does) fail:PS VinsWorldcom ~ > reg query HKLM\SOFTWARE\Notepad++ ERROR: The system was unable to find the specified registry key or value.Not to throw in wrench in the works (if you can dodge a wrench, …) but that (read: portable installation) may or may not be a corner case you care about.
Cheers.
-
@PeterJones great, thanks!
-
@Michael-Vincent yep, there’s already something in place to work with portable versions. thanks though!
-
@OpossumPetya I get
ERROR: The system was unable to find the specified registry key or value.It’s on a machine that started as Windows 10 and when Windows Update offered Windows 11 I took it.
For historical reasons I installed the 32-bit version of Notepad++ and these days routinely update by running the installer.exe. I don’t have a Notepad++ key under HKLM\SOFTWARE\
My Notepad++ debug info shows:
Notepad++ v8.6.4 (32-bit) Build time : Feb 20 2024 - 00:11:10 Path : C:\Program Files (x86)\Notepad++\Notepad++.exe Command Line : Admin mode : OFF Local Conf mode : OFF Cloud Config : OFF OS Name : Windows 11 Home (64-bit) OS Version : 22H2 OS Build : 22621.3155 Current ANSI codepage : 1252 Plugins : DSpellCheck (1.5) PythonScript (2)As I normally run everything from the command line and not the GUI my np.bat script finds Notepad++.exe using the two default paths that Notepad++'s installer.exe typically uses.
set NPPATH=%ProgramFiles%\Notepad++\notepad++.exe if exist "%NPPATH%" goto :run-npp if defined ProgramFiles(x86) set NPPATH=%ProgramFiles(x86)%\Notepad++\notepad++.exe if exist "%NPPATH%" goto :run-npp rem rem there's more where it looks for portable copies. rem rem If the script can't find a copy of Notepad++ it instead runs rem Microsoft Notepad.exe though also does argument expansion, rem wildcards, etc. that Microsoft Notepad can't handle on its own.FWIW, I have a 64 bit
c:\Program Files\Notepad++\contextMenu\NppShell.dllthat I suspect is an artifact of installing a 64-bit version at some point before switching back to my usual 32-bit installed version. Thec:\Program Files\Notepad++folder is empty other than the...\contextMenu\NppShell.dllfile. The registry points to the 32-bitc:\Program Files (x86)\Notepad++\contextMenu\NppShell.dll. If I rename that file then “Edit with Notepad++” disappears as a right click option for Windows Explorer. I rename the file back toNppShell.dlland “Edit with Notepad++” immediately reappears.Thus, you may be able to find an installed copy of Notepad++ by looking to see if there is a context menu handler. I don’t know how NppShell.dll finds the copy of Notepad++.exe that it runs.
On my machine
start Notepad++works from a command prompt works. I believe that uses the same mechanism that Explorer.exe uses to find a copy of Notepad++.exe. I see that cmd.exe is the parent process when I start Notepad++.exe like this meaning it’s not passing the request on to Explorer.If your goal is to run Notepad++ then I would use
start Notepad++and let Windows deal with the legwork of tracking down the executable. -
@OpossumPetya said in Finding out install location - could you try on cmd?:
C:\>for /f "tokens=2 delims=REG_SZ" %i in ('reg query HKLM\SOFTWARE\Notepad++ ^| findstr /i /l /c:"Default"') do @echo %i 2> NUL C:\Program Files\Notepad++ C:\>delimsoperates on characters, not words so a path that contains any character ofR,E,G,_,S,Zwill echo a incomplete path. For example in a batch file:for /f "tokens=2 delims=REG_SZ" %%A in ( 'echo (Default^) REG_SZ C:\Program Files\rReEgG__sSzZ' ) do ( echo %%A )echoes
C:\Program Files\rasRis a delimiter andeis the next token.This is what I have tried so far to echo both x86 and x64 install paths of Notepad++
setlocal if defined ProgramW6432 ( set "bit=/reg:32 /reg:64" ) else ( set bit="" ) for %%Z in (%bit%) do ( for /f "tokens=1,2,*" %%A in ( '2^>nul reg query HKLM\Software\Notepad++ /ve %%~Z' ) do if "%%~A" == "(Default)" if "%%~B" == "REG_SZ" ( if not "%%~C" == "(value not set)" ( echo "%%~Z" "%%~C" ) ) )It also echoes the bit arg to let you know where the data came from. The bit arg will be empty if
ProgramW6432is not defined. I cannot specify if the bit arg is valid on Windows Vista or XP as no records available and do not have a VM for those OSes setup currently to test.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login