I wrote an application to accept a filepath (file with custom extension) as an argument and then do some processing on it.
The idea being that I could associate (using windows functionality) the custom file with my executable app that I install (via install shield installer).
I would like to be able to double-click my file with the custom extension and have it passed to my executable for processing.
However, the behaviour I get is this:
- if I double click my file (with the custom extension) it does nothing.
- if I drag and drop the file on to my executable program then it works as expected.
So is it possible to get this to work by simply double-clicking my custom file?
I guess windows is attempting to open the custom file using the executable which maybe is not the same as passing it in as an argument?!
Any help appreciated.
thanks,
KS
Using InstallShield 2013:
For A Custom File Type
- Switch to the "Installation Designer" tab.
- In the frame on the left, expand "Organization" and select "Components".
- From the list of Components, expand options for your primary exe, then expand "Advanced Settings" and select "File Types".
- Right click "Extensions" and select "New Extension". Enter the extension WITHOUT a leading period.
- Your extension should have had the "verb" "Open" automatically added for it when you created it. Select that. Enter a "Display Name" e.g. "&Open with MyApp". Enter an "Argument" e.g. "%1" (that passes the file name to the exe wrapped in quotes to handle long filenames/spaces.)
- Select your new extension from the list, then type in a "ProgID" for it. For example, "MyApp.Document".
To define a specific icon to associate with the type (rather than the implicit exe icon):
- Click on the "ProgID" you added ("MyApp.Document" or whatever). Click in the "Icon" field, then click the "..." button which appears. That will allow you to browse to an icon file.
For A "Common" File Type
If a file type doesn't "belong" to your application exclusively, you may want to add your application to the list of choices for opening that type, but without making it the default program, or changing the default icon. Here's how to achieve that...
- Switch to the "Installation Designer" tab and follow the instructions for a Custom File Type.
- In the frame on the left, expand "Organization" and select "Components".
- From the list of Components, expand options for your primary exe, then select "Registry Data".
- In the "Destination Computer Frame", right-click on "HKEY_CLASSES_ROOT" and select "New"..."Key". Name the key the file extension (INCLUDING the leading peroid) for which you are defining the association.
- Right-click on that new key and select "New"..."Default Value". Then, right click on that default value, select "Modify". Enter the ProgID for the what should be the default application to open this type and dicate the icon. You may need to check the registry to determine this value. For example, the standard default for a zip file is "CompressedFolder". Figuring this out is the most tricky part to this procedure.
- Right-click on that new key and select "New"..."Key" again to create a sub key. Name the sub key "OpenWithProgids".
- Right-click on the "OpenWithProgids" key and select "New"..."String Value". Name that value the ProgId you defined to be the default. Leave this value "empty" (the "name" is the "value").
- Right-click on the "OpenWithProgids" key and select "New"..."String Value" again. This time, name the value the ProgId you defined for your application when you followed the instructions for a Custom File Type.
Whatever your installation method is (installscript, MSI, etc) you basically need to create a few HKEY_CLASSES_ROOT entries. Depending on your method, there are different ways to go about it (for example in an MSI installer created by installshield if you follow the guidelines it can also trigger an installation repair for your application if it detects there are problems.
The root you need though: (we'll pretend your extension is .xyz)
- Under HKCR create a new key named ".xyz" (you can see many others here for example
- In the default value, set the data to some name that means something like "myapp.xyz"
- Create a new HKCR key named "myapp.xyz" to match what you created in 2
- In the default value, set the data to a descriptive label. For example "My App Data File"
- Create a subkey called shell (you can set the default value here to "open", which will then make open the default action in explorer)
- Create a subkey called open
- Create a subkey called command
- In the default value of the command key set the value to be "c:\path\to\installfolder\appname.exe" "%1" (note all quotes in this instance matter)
- You can also create a subkey under "myapp.xyz" called DefaultIcon, which points to an icon file that will be associated with your extension in explorer.
If you use installshield, a lot of the above is done for you; though I've had to tweak it in the past to make it match the desired output in more complex applications with multiple file formats.