0
votes

I did a software in Python, wrapped in an NSIS installer for Windows. I have data files in my software and I want to be able to edit them by clicking on an "Edit" button in my GUI. My problem is that those data files have a new file extension, so when I try to open it using os.startfile(), Windows tells me it does not know which application to use for opening them.

I don't want to call a particular text editor, I want to use the default editor configured for text files on the system (i.e. sublime for me but notepad for my neighbor...).

I tried adding a key in the Windows registry for my extension with NSIS, saying it is "PerceivedAs" textfile but it does not change anything.

Is it possible to add something to the Windows registry to tell it to open a specific extension with the default txt editor?

Is itpossible in Python to open a file with an unknown extension using the default txt editor?

1
It is PerceivedType, not PerceivedAs.Anders

1 Answers

0
votes

Windows does not have a default text editor. Internet Explorer does have the concept of a default editor but unless we are taking about html/xml it is probably not the best choice.

What you can do in a running application however is to manually call ShellExecuteEx with a forced class. To do that you should figure out the ProgId for the .txt extension and then use that HKEY or ProgId as the forced class.

On Windows XP and later you should be able to configure the file type by adding a PerceivedType to your extension in the registry:

WriteRegStr HKLM "Software\Classes\.sbt" "PerceivedType" "text"

If you want to use the existing .txt association as a open with option:

ReadRegStr $0 ShCtx "Software\Classes\.txt" "" ; Find the progid (not 100% correct but doing it correctly is a lot of work)
StrCmp $0 "" 0 +2
    StrCpy $0 txtfile
WriteRegNone HKLM "Software\Classes\.sbt\OpenWithProgids" "$0"