Advertisement
zippy1981

Looking for the Office install folder.

Aug 11th, 2015
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. // Taken from https://support.microsoft.com/en-us/kb/240794
  2.  
  3. RegistryKey[] keys;
  4. if (IntPtr.Size == 8) {
  5.     keys = new[] {
  6.         RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry32),
  7.         RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64),
  8.     };
  9. }
  10. else {
  11.     keys = new[] {
  12.         RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Default)
  13.     };
  14. }
  15.  
  16. const string excelProgId = "Excel.Application";
  17. foreach(var key in keys) {
  18.     var excelClassIdPath = string.Format(@"Software\Classes\{0}\CLSID", excelProgId);
  19.     var excelClassIdKey = key.OpenSubKey(excelClassIdPath);
  20.     if (excelClassIdKey == null) continue;
  21.     var excelClassId = excelClassIdKey.GetValue(null);
  22.     var excelLocationPath = string.Format(@"HKEY_LOCAL_MACHINE\Software\Classes\CLSID\{0}\LocalServer32", excelClassId);
  23.     var excelLocation = key.OpenSubKey(excelLocationPath).GetValue(null);
  24.  
  25.     new {
  26.         Name = "Excel",
  27.         ProgId = excelProgId,
  28.         ClassId = excelClassId,
  29.         Path = excelLocation
  30.     }.Dump();
  31.     break;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement