file associations (file types to open with npp)
-
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? -
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.
-
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
-
I think I might have fixed it
https://textuploader.com/1awt2/raw
-
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.1I wish they could be merged, can they?
-
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()
-
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?
-
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. -
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 :-)