Let's assume you know how to read the registry. You can get all the functions you need here:
http://msdn.microsoft.com/en-us/library/ms724875.aspx[
^].
Let's say you have the extension ".ext" (substitute the value of your variable holding the extension parameter, with starting dot). I will illustrate the procedure using my system on the example of the extension ".pdf".
Here is the pseudo-code:
- Get to the registry key
HKEY_CLASSES_ROOT\.pdf
- Get default value for this key; assign to some variable
key_default
. On my system, key_default == "AcroExch.Document" - Get to the registry key
HKEY_CLASSES_ROOT\
, concatenate it with key_default
. On my system, it is "HKEY_CLASSES_ROOT\AcroExch.Document" - Go to the sub-key of the key found on the previous step by adding "
\Shell\Open\Command
" (concatenate from right). On my system it's "HKEY_CLASSES_ROOT\AcroExch.Document\Shell\Open\Command". - Get default value for this key. This is a command line used to open the file with the registered extension using the Shell. On my system, it is a full path the Adobe acrobat viewer: "..\\AcroRd32.exe" "
%1
". The parameter "%1
" is given in the format of Windows batch file. It means that if you put the whole string in the batch file, you can call this batch with the parameter representing the full data file name; the file should be of the type defined by the extension you've started with. - To load the file with the application registered for a give file extension you need to run the application using the path name with the parameter specifier "%1" substituted with the actual file name.
Problem solved.
—SA