Community
    • Login

    Finding out install location - could you try on cmd?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    7 Posts 5 Posters 1.9k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • OpossumPetyaO
      OpossumPetya
      last edited by OpossumPetya

      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 %i
      

      Here’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!

      PeterJonesP Michael VincentM mkupperM mpheathM 4 Replies Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @OpossumPetya
        last edited by

        @OpossumPetya ,

        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:

        • https://github.com/notepad-plus-plus/notepad-plus-plus/blob/40adc3820140c5a52d134a7f7085e328776bec99/PowerEditor/installer/nsisInclude/uninstall.nsh#L154

        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.

        OpossumPetyaO 1 Reply Last reply Reply Quote 1
        • Michael VincentM
          Michael Vincent @OpossumPetya
          last edited by

          @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 regedit query 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.

          OpossumPetyaO 1 Reply Last reply Reply Quote 1
          • OpossumPetyaO
            OpossumPetya @PeterJones
            last edited by

            @PeterJones great, thanks!

            1 Reply Last reply Reply Quote 0
            • OpossumPetyaO
              OpossumPetya @Michael Vincent
              last edited by

              @Michael-Vincent yep, there’s already something in place to work with portable versions. thanks though!

              1 Reply Last reply Reply Quote 2
              • mkupperM
                mkupper @OpossumPetya
                last edited by

                @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.dll that I suspect is an artifact of installing a 64-bit version at some point before switching back to my usual 32-bit installed version. The c:\Program Files\Notepad++ folder is empty other than the ...\contextMenu\NppShell.dll file. The registry points to the 32-bit c:\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 to NppShell.dll and “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.

                1 Reply Last reply Reply Quote 3
                • mpheathM
                  mpheath @OpossumPetya
                  last edited by

                  @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:\>
                  

                  delims operates on characters, not words so a path that contains any character of R, E, G, _, S, Z will 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\r as R is a delimiter and e is 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 ProgramW6432 is 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.

                  1 Reply Last reply Reply Quote 2
                  • First post
                    Last post
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors