Community
    • Login

    file associations (file types to open with npp)

    Scheduled Pinned Locked Moved General Discussion
    41 Posts 4 Posters 9.2k 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.
    • SalviaSageS
      SalviaSage
      last edited by

      Hi.

      I understand how to edit the registry really well.
      I think it would be a nice idea to set all the file associations you want for np++ using a .reg file.

      Can you elaborate more on what it is that you are trying to do?
      Then, I can try to write something for you.

      1 Reply Last reply Reply Quote 1
      • patrickdrdP
        patrickdrd
        last edited by

        I want to store the associations I use to open npp with in a reg file and
        store it in the npp portable installation and use it on any pc (work/home/desktop/laptop/new pc etc.),
        if it’s possible?

        1 Reply Last reply Reply Quote 0
        • SalviaSageS
          SalviaSage
          last edited by

          Yes, I think this is possible using a .reg file.

          Basically, the .reg file would change the default file associations of those extensions such as .txt .md .xml and whatever extension
          to open with np++ on double click.

          This would obviously override any other file associations that other programs make also.

          You can give me a list of extensions that you want associated with np++, then I will try working on this .reg file
          when I have the time.

          See you.

          1 Reply Last reply Reply Quote 0
          • patrickdrdP
            patrickdrd
            last edited by

            thanks

            txt
            java
            properties
            sql
            tql
            pld
            fnc
            pkb
            pks
            prc
            trg
            tpb
            tps
            vw
            ttx
            cfg
            css
            diz
            log
            nfo
            ora
            ini
            srt
            xml
            dat
            json
            opml
            
            1 Reply Last reply Reply Quote 0
            • patrickdrdP
              patrickdrd
              last edited by

              I think I might have fixed it

              https://textuploader.com/1awt2/raw
              
              1 Reply Last reply Reply Quote 1
              • patrickdrdP
                patrickdrd
                last edited by

                actually I didn’t,
                this one:
                https://textuploader.com/1awt2/raw
                seems to work fine in windows 7,
                while this one:
                https://textuploader.com/1aw6a/raw
                seems to work in windows 8.1

                I wish they could be merged, can they?

                Eko palypseE 1 Reply Last reply Reply Quote 1
                • Eko palypseE
                  Eko palypse @patrickdrd
                  last edited by Eko palypse

                  @patrickdrd

                  what about using a script like this?
                  For setting it per machine it must run under administrative privileges .
                  The FILE_EXT list would be the place to maintain your file extensions.

                  import ctypes
                  import ctypes.wintypes as wintypes
                  from Npp import notepad, MESSAGEBOXFLAGS
                  
                  shell32 = ctypes.WinDLL('shell32')
                  advapi32 = ctypes.WinDLL('advapi32')
                  
                  SHCNE_ASSOCCHANGED = 0x08000000
                  SHCNF_IDLIST = 0
                  
                  HKEY_CURRENT_USER = -2147483647
                  HKEY_LOCAL_MACHINE = -2147483646
                  SUB_KEY = u'Software\Classes\{}'
                  KEY_ALL_ACCESS = 0xf003f
                  REG_SZ = 1
                  ERROR_SUCCESS = 0x0
                  
                  FILE_EXT = ['.txt', '.xml']
                  NPPNAME = ctypes.create_unicode_buffer(u'Notepad++_file')
                  
                  def main():
                      result = notepad.messageBox(('YES for USER only\n\n'
                                                   'NO for MACHINE\n\n'
                                                   'CANCEL to abort'), 'FileExtension Registration', 3)
                  
                      if result == MESSAGEBOXFLAGS.RESULTYES:
                          _HKEY = HKEY_CURRENT_USER
                      elif result == MESSAGEBOXFLAGS.RESULTNO:
                          _HKEY = HKEY_LOCAL_MACHINE
                      else:
                          return
                  
                      for extension in FILE_EXT:
                          _sub_key = SUB_KEY.format(extension)
                          try:
                              phkResult = wintypes.HKEY()
                              result = advapi32.RegOpenKeyExW(_HKEY,
                                                              _sub_key,
                                                              0,
                                                              KEY_ALL_ACCESS,
                                                              ctypes.byref(phkResult))
                              if result == ERROR_SUCCESS:
                                  result = advapi32.RegSetValueExW(phkResult,
                                                                   None,
                                                                   0,
                                                                   REG_SZ,
                                                                   NPPNAME,
                                                                   len(NPPNAME) * ctypes.sizeof(wintypes.c_wchar))
                                  if result == ERROR_SUCCESS:
                                      print(u'key {} successfully set'.format(_sub_key))
                                  else:
                                      print(u'Aborting as error {} occured'.format(result))
                                      break
                  
                              else:
                                  print('ERROR {} opening key {}'.format(result, _sub_key))
                                  break
                          except Exception as e:
                              print('ERROR:{}'.format(e))
                          finally:
                              advapi32.RegCloseKey(phkResult)
                  
                      result = notepad.messageBox('Should the system be informed about the changes?', 'Inform System', 4)
                      if result == MESSAGEBOXFLAGS.RESULTYES:
                          shell32.SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, None, None)
                  
                  main()
                  
                  1 Reply Last reply Reply Quote 3
                  • patrickdrdP
                    patrickdrd
                    last edited by patrickdrd

                    looks good, but how do I run it?
                    this should be a PowerShell script, right?
                    can you post a batch file to call it with administrative privileges please?

                    also, where is npp in this script?

                    1 Reply Last reply Reply Quote 0
                    • Eko palypseE
                      Eko palypse
                      last edited by

                      sorry for confusion, it is a python script.
                      As I read some of your posts I got the impression that you are using pythonscript plugin.

                      1 Reply Last reply Reply Quote 0
                      • patrickdrdP
                        patrickdrd
                        last edited by

                        yes, I am, but I’m not that familiar with it, actually I’ve forgotten, so either you send me instructions or I’ll dig older posts

                        1 Reply Last reply Reply Quote 1
                        • Eko palypseE
                          Eko palypse
                          last edited by Eko palypse

                          If you have the python script plugin installed, just create a new script and copy/paste the posted script.
                          Save it. Restart npp as admin if you want to set the extensions on LOCAL_MACHINE key and execute the script. If it should be set under CURRENT_USER a non-admin start of npp is sufficient.

                          1 Reply Last reply Reply Quote 3
                          • patrickdrdP
                            patrickdrd
                            last edited by

                            ok, thanks a lot, I’ll try it in the morning in both pc’s and I’ll tell you

                            1 Reply Last reply Reply Quote 1
                            • patrickdrdP
                              patrickdrd
                              last edited by

                              it didn’t work

                              1 Reply Last reply Reply Quote 0
                              • patrickdrdP
                                patrickdrd
                                last edited by

                                I tried both my scripts on a windows 2008r2 server and
                                the windows7 script worked, the 8.1 not,
                                strange that the 8.1 works on my home laptop

                                1 Reply Last reply Reply Quote 1
                                • Eko palypseE
                                  Eko palypse
                                  last edited by

                                  Did you get one of the possible errors or the message that key xyz has been successfully set?
                                  Note, you have to open the python script plugin console to see the messages.
                                  If the message is successfully set then I assume that the machine does not have a proper npp
                                  installation, means, the link Notepad++_file is either not set at all or points to a wrong path etc…

                                  1 Reply Last reply Reply Quote 1
                                  • patrickdrdP
                                    patrickdrd
                                    last edited by

                                    if you had opened my reg file(s),
                                    maybe you would have seen that I’m running npp portable in all the machines,
                                    that’s why I asked after you posted it “where is npp in this script”,

                                    after this post I think that specifying the npp path is needed,
                                    in my case it is “D:\Utilities\PortableApps\Notepad++”

                                    1 Reply Last reply Reply Quote 0
                                    • Eko palypseE
                                      Eko palypse
                                      last edited by Eko palypse

                                      I’ve opened the reg files but I didn’t understand what you trying to ask.
                                      So what would you suppose? Making a workflow like

                                      A.)
                                      Check if Notepad++_file link is found
                                      if found, run the script like it is now
                                      if not found, open a dialog and asking if such a key should be created?
                                      or
                                      B.)
                                      something else in mind?

                                      1 Reply Last reply Reply Quote 1
                                      • patrickdrdP
                                        patrickdrd
                                        last edited by

                                        no, can’t it be set inside the script like in a constant variable?

                                        1 Reply Last reply Reply Quote 0
                                        • Eko palypseE
                                          Eko palypse
                                          last edited by

                                          Of course ;-) - that was what I meant.
                                          Doing everything within the script.

                                          1 Reply Last reply Reply Quote 1
                                          • patrickdrdP
                                            patrickdrd
                                            last edited by

                                            that’s what I meant too, within the script is fine,
                                            running the script once every time a new machine is setup is fine as well of course

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