file associations (file types to open with npp)
-
I’m working with a reg file for a while,
in order to create my npp associations and use it when I format/change pc/laptop etc.well, I found out recently that it doesn’t work, as expected at least,
first of all, for txt files I use:
[-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] [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.txt] "PerceivedType"="text" @="txtfile" "Content Type"="text/plain" [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.txt\OpenWithProgids] "txtfile"=hex(0): [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.txt\DefaultIcon] @="\"D:\\Utilities\\PortableApps\\Notepad++\\notepad++.exe\",0" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.txt\shell\open\command] @="\"D:\\Utilities\\PortableApps\\Notepad++\\notepad++.exe\" \"%1\"" [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.txt\UserChoice] "ProgId"="txt_auto_file" "Hash"="q4kw7ShKh2M="
I clean them all and then I re-create from scratch,
- do I need all of these entries?
also, - what is this hash that is created everytime I assign npp to always open txt files? is it needed? I tried to run the above reg script on a windows 7 machine and it didn’t work (trying to open a .txt file afterwards requested that I specify which program I want it to open with), while they work on my laptop, which is windows 8.1
- do I need all of these entries?
-
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. -
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.