|
|
Question : File association "Windows Open With?"
|
|
I wrote a perl text editor and have added support for target file to be opened via a command line argument. I have also compiled the script into a win32 executable using perl2exe. I want to be able to left click a file and be able to choose my executable to open the file via the "Open With" menu.
As of now when I try to browse for my executable to open these files with and choose the executable the perl command line interpretor gets added to the list and not the program iself. Why is this? And how do I get Windows to accept my executable as a valid program for opening text files?
|
Answer : File association "Windows Open With?"
|
|
I'm assuming that you are using an installer program to get your software installed on a user's machine. (If not, check out http://www.jrsoftware.org/isinfo.php for Inno Setup, an excellent and free install system for commercial or private use.)
In order to be a candidate for the Open With menu, your program only needs to exist in the HKEY_CLASSES_ROOT registry key. You do not need any file extentions associated, although you can do that too.
Here is a sample registry file that you can use as a template:
; Begin registry code.
; Lines starting with a semicolon are comments
[HKEY_CLASSES_ROOT\YourProgram] ; This name is displayed in Windows Explorer in the ; "File Type" column. @="YourProgram file"
[HKEY_CLASSES_ROOT\YourProgram\shell]
[HKEY_CLASSES_ROOT\YourProgram\shell\open] ; Use the ampersand (&) to denote the underlined letter. @="Open with &YourProgram"
[HKEY_CLASSES_ROOT\YourProgram\shell\open\command] ; Backslashes and quotes must be escaped with a backslash. ; %n = nth command-line parameter. @="C:\\PATH\\TO\\YourProgram.exe \"%1\""
[HKEY_CLASSES_ROOT\YourProgram\DefaultIcon] ; The number after the comma is the zero-based index of the icon to use for ; any files that are associated with your program, and it is displayed in the ; "Open With" dialog box. Use ",0" if your program has only one icon resource. @="C:\\PATH\\TO\\YourProgram.exe,0"
; To associate files with your program, do this:
; Change ".xyz" to the actual file extension. ".txt" for example. [HKEY_CLASSES_ROOT\.xyz] ; The mime type is used in browsers and stuff - you can ignore it if your file ; format is proprietary. For example, "text/plain" for text files. If your ; format is binary, use "application/octet-stream" for compatibility. "Content Type"="mime/type" ; This MUST be the name of the registry key created earlier. This is how ; Windows knows what to open the file with. @="YourProgram"
; End registry code
Hope this helps! ISTool, a program for Inno Setup, can create all this junk for you. Just choose "Project > Create Association". ISTool is linked to on the Inno Setup website.
|
|
|
|
|