file associations (file types to open with npp)
-
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
-
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. -
ok, thanks a lot, I’ll try it in the morning in both pc’s and I’ll tell you
-
it didn’t work
-
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 -
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 linkNotepad++_file
is either not set at all or points to a wrong path etc… -
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++” -
I’ve opened the reg files but I didn’t understand what you trying to ask.
So what would you suppose? Making a workflow likeA.)
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? -
no, can’t it be set inside the script like in a constant variable?
-
Of course ;-) - that was what I meant.
Doing everything within the script. -
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 -
Ok, I will try to come up with a solution later this day.
Lunch break if over.While thinking about the dialog to ask for confirmation about
creating the Notepad++_file link - does it really makes sense?
I mean, if one runs the script the idea is to have the extensions
registered and this means you need to have the key.
I guess silently setting the key is ok.Other question to everyone reading this,
Does someone know a way to refresh the icon cache?
Currently, if you run the script and, let’s say you want to register
.xml to be opened with npp, you still see the previous icon until
you logon/logoff.
It would be nice if I could force to reload the icon cache so that the
npp icon is shown. I haven’t found any good side describing what
needs to be done yet.Have to go back to work :-)
-
don’t worry, I’m not in a hurry,
this thread will be active for a while,
I’ll be waiting for SalviaSage’s reply tooas for the your question, yes, silent is fine,
if I was writing the script,
I would choose machine silently too -
Hopefully this does what you are looking for.
The problem with the icon cache reload is still not solved.import ctypes import ctypes.wintypes as wintypes from Npp import notepad, MESSAGEBOXFLAGS # modify this two variables to your needs # ------------------------------------------------------------------------------------------------------------------------ NPP_FULL_PATH = u'D:\\PortableApps\\Npp\\notepad++.exe' FILE_EXT = ['.txt','.xml'] # ------------------------------------------------------------------------------------------------------------------------ shell32 = ctypes.WinDLL('shell32') advapi32 = ctypes.WinDLL('advapi32') SHCNE_ASSOCCHANGED = 0x08000000 SHCNF_IDLIST = 0 HKEY_CURRENT_USER = -2147483647 HKEY_LOCAL_MACHINE = -2147483646 KEY_ALL_ACCESS = 0xf003f REG_SZ = 1 ERROR_SUCCESS = 0x0 SUB_KEY = u'Software\\Classes\\{}' NPPNAME = u'Notepad++_file' DOCTYP = u'Notepad++ Document' NPP_ICON = u'"{}",0'.format(NPP_FULL_PATH) NPP_COMMAND = u'"{}" "%1"'.format(NPP_FULL_PATH) def set_reg_value(root_key, value): try: result = advapi32.RegSetValueExW(root_key, None, 0, REG_SZ, value, len(value) * ctypes.sizeof(wintypes.c_wchar)) if result == ERROR_SUCCESS: print('successfully set {}'.format(value)) else: notepad.messageBox('Aborting as error {} occured'.format(result), 'ERROR', MESSAGEBOXFLAGS.ICONERROR) except Exception as e: raise IOError('{}'.format(e)) finally: advapi32.RegCloseKey(root_key) def create_reg_entries(root_key, sub_key): try: phkResult = wintypes.HKEY() dwDisp = wintypes.DWORD() result = advapi32.RegCreateKeyExW(root_key, sub_key, 0, None, 0, KEY_ALL_ACCESS, None, ctypes.byref(phkResult), ctypes.byref(dwDisp) ) if result == ERROR_SUCCESS: if dwDisp.value in [1, 2]: print '\nKey {} has been {}'.format(sub_key, 'created' if dwDisp == 1 else 'opened') else: notepad.messageBox('Unexpected disposition value received:{}'.format(dwDisp), 'WARNING', MESSAGEBOXFLAGS.ICONWARNING) except Exception as e: advapi32.RegCloseKey(root_key) raise IOError('{}'.format(e)) return phkResult def create_npp_link(root_key): _key = create_reg_entries(root_key, SUB_KEY.format(NPPNAME)) set_reg_value(_key, DOCTYP) _key = create_reg_entries(root_key, SUB_KEY.format(u'Notepad++_file\\DefaultIcon')) set_reg_value(_key, NPP_ICON) _key = create_reg_entries(root_key, SUB_KEY.format(u'Notepad++_file\\shell\\open\\command')) set_reg_value(_key, NPP_COMMAND) return True def register_extensions(root_key): for extension in FILE_EXT: _key = create_reg_entries(root_key, SUB_KEY.format(extension)) set_reg_value(_key, NPPNAME) return True 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 if create_npp_link(_HKEY): if register_extensions(_HKEY): 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) else: notepad.messageBox('Unable to open or create Notepad++_file key', 'ERROR', MESSAGEBOXFLAGS.ICONERROR) main()
-
no, it doesn’t,
e.g. I deleted already registered txt file with[-HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.txt] [-HKEY_LOCAL_MACHINE\SOFTWARE\Classes\txt] [-HKEY_CURRENT_USER\SOFTWARE\Classes\.txt] [-HKEY_CURRENT_USER\SOFTWARE\Classes\txt] [-HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.txt\UserChoice] [-HKEY_CURRENT_USER\Software\Microsoft\Windows\Roaming\OpenWith\FileExts\.txt\UserChoice]
and tried yours and no error was shown but when tried to open .txt file it asked what I wanted to open it with
-
I think I fixed it to work in windows 8.1 and windows 7:
https://textuploader.com/1awwn/raw
I found out that some files need the “hash” in registry which is awkward,
because I don’t know if it will work in another pc,
but I don’t have another 8.1,
so if anyone wants to test it -
-
:-( - although I can see why securing it might be a good choice. Too bad - at least I learnt something new. :-)
-
With Windows 10, at least, the good old fashioned
HKCR\.ext (Default)=SomeAction
andHKCR\SomeAction\command (default)=notepad++ "%1"
still works for me, and I thought if it worked in Win7 and works in Win10, it would work in Win8. But I could be wrong.An example of me recently verifying that the old-style assocation works can be found on superuser. maybe it’s because the .0-.9 extensions were ones that weren’t already being interfered with using the Classes/FilesExts assocation.
-
But, afaik, you shouldn’t use HKEY_CLASSES_ROOT as this, itself, isn’t a persistent key.
It’s just another view of keys stored in HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER.
I’m unsure what kind of issue would possibly rise if one corrupts HKCR.