Saturday, June 2, 2012

File Extension Association in Setup Factory (No restart needed)

When installing our software, usually, we need to associate a file extension to the files which the software exclusively worked with them. It is simple and straightforward in Setup Factory. You just need to add the proper values in the windows registry. To do this, add the below code to the "On Post Install" actions of the Setup Factory. (I use version 9)


Registry.SetValue(HKEY_CLASSES_ROOT, ".ext", "", "Software Name", REG_SZ);
Registry.SetValue(HKEY_CLASSES_ROOT, "Software Name\\shell\\open\\command", "", SessionVar.Expand("\"%AppFolder%\\MyApplication.exe\" \"%1\""), REG_SZ);
Registry.SetValue(HKEY_CLASSES_ROOT, "Software Name\\DefaultIcon", "", SessionVar.Expand("%AppFolder%\\MyApplication.exe,0"), REG_SZ);


Where ".ext" is the file extension for your software data files, "Software Name" is the title of your software, and "MyApplicaton.exe" is the executable file which loads the data files as its parameter. I supposed that you already added the icon of your software to the Setup Factory as DefaultIcon.
Everything is done with the above piece of code; but you need to restart your computer for the file association to work with the new extension. 


There is another solution to complete the task directly from the Setup Factory without restarting the windows. You just need to add the below line to the above code:


DLL.CallFunction(_SystemFolder.."\\Shell32.dll", "SHChangeNotify", "134217728, 0, 0, 0", DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL); 


That's all. Everything should be worked fine now.