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.
Modifying Windows registry is a common task for applications. The installed Comodo Internet Security as the anti virus on my computer. Each time I compile a native application and running it via the Embarcadero C++Builder, Comodo shows me a "Unrecognized Application" message and runs it in the Sand Box.
I always click on the "Don't isolate it again" link on the Comodo message box. Usually after a few times of clicking on the mentioned link, Comodo will not show the message again. I thought that it remembers my answer and lets the application to run normally.
When I called the functions which try to modify Windows registry, I noticed that it can not open the registry at all. This problem wastes lots of my time. I found that Comodo runs the application in the Sand Box, so it can not read or modify Windows registry keys values.
If you have such a kind of problem, check you anti virus which may prevent the application to have access to the Windows registry. For me, I disable the Defence+ feature of Comodo to be able to run the application normally when programming.