Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Taken from https://support.microsoft.com/en-us/kb/240794
- RegistryKey[] keys;
- if (IntPtr.Size == 8) {
- keys = new[] {
- RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry32),
- RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64),
- };
- }
- else {
- keys = new[] {
- RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Default)
- };
- }
- const string excelProgId = "Excel.Application";
- foreach(var key in keys) {
- var excelClassIdPath = string.Format(@"Software\Classes\{0}\CLSID", excelProgId);
- var excelClassIdKey = key.OpenSubKey(excelClassIdPath);
- if (excelClassIdKey == null) continue;
- var excelClassId = excelClassIdKey.GetValue(null);
- var excelLocationPath = string.Format(@"HKEY_LOCAL_MACHINE\Software\Classes\CLSID\{0}\LocalServer32", excelClassId);
- var excelLocation = key.OpenSubKey(excelLocationPath).GetValue(null);
- new {
- Name = "Excel",
- ProgId = excelProgId,
- ClassId = excelClassId,
- Path = excelLocation
- }.Dump();
- break;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement