Link to home
Start Free TrialLog in
Avatar of pepr
pepr

asked on

How can I get the full path to the MS Excel (Excel.exe) from the registry?

Hi,

How can I reliably get the full path to the Excel executable from the registry?  The main goal is to get the detailed information about the version from the Excel.exe.

So far, I was successfull using the following approach, but it is not ideal, and there could be something better (symbolically, simplified):

    // Get the CLSID of the Excel.
    RegOpenKeyEx(HKEY_CLASSES_ROOT,  TEXT("Excel.Application\\CLSID"), 0, KEY_READ, &hKey); 
    RegQueryValueEx(hKey, TEXT(""), NULL, &ValueType, buf, &buflen);

    // I have got the value "{00024500-0000-0000-C000-000000000046}" for Excel 2007 in buf.

    // Get the LocalServer value.
    RegOpenKeyEx(HKEY_CLASSES_ROOT, "CLSID\\" + buf + "\\LocalServer",  0, KEY_READ, &hKey);

    // I have got the value "C:\PROGRA~2\MICROS~1\Office12\EXCEL.EXE /automation"
    // Notice the shortened directory names.

    [Remove the option /automation and text whether the file exist -- I want to check if the file physically 
     exists (not only to check that the info is present in the registry).]

    [call the GetFileVersionInfo() for the filename (version.lib must be linked).]

    // I get the string like "12.0.6557.5000"

Open in new window


Is the HKCR\CLSID\{...}\LocalServer the good or the best way to get somehow the path to the Excel.exe?  Can the path with shortened subdir names be expanded to full path? (I would like to include it to the error log if anything wrong happens.)

Thanks for your time and experience,
    Petr
ASKER CERTIFIED SOLUTION
Avatar of Zoppo
Zoppo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pepr
pepr

ASKER

Hi Zoppo.  Thanks, but I prefer not to use another library.  Also, I am not sure if the .xls must always be associated with the Excel.exe (say it could be the OpenOffice Calc).  This will not run on my machine.

For others, I have found the http://support.microsoft.com/kb/240794/en-us that uses basically the same approach as I did, but with the HKEY_CLASSES_ROOT is replaced by HKEY_LOCAL_MACHINE\Software\Classes\.  I have also found the function GetLongPathName() that is capable to convert the path with 8.3 names to the long path.  I will post the final code when finished (later).
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pepr

ASKER

Thanks for the help.