Created
January 12, 2024 13:54
-
-
Save smithnigelw/eaad13b6bcfca5b6cb897fa2041ff107 to your computer and use it in GitHub Desktop.
Checks the Windows Registry for details relating to "Microsoft.ACE.OLEDB" and "Microsoft.Jet.OLEDB"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Microsoft.Win32; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
const string searchKey1 = "Microsoft.ACE.OLEDB"; | |
const string searchKey2 = "Microsoft.Jet.OLEDB"; | |
using (RegistryKey baseKey = Registry.ClassesRoot) | |
{ | |
foreach (string keyName in baseKey.GetSubKeyNames()) | |
{ | |
if (keyName.StartsWith(searchKey1, StringComparison.OrdinalIgnoreCase) || | |
keyName.StartsWith(searchKey2, StringComparison.OrdinalIgnoreCase)) | |
{ | |
Console.WriteLine($"{keyName}"); | |
string clsid = GetClsid(baseKey, keyName); | |
if (!string.IsNullOrEmpty(clsid)) | |
{ | |
CheckRegistryPathsForClsid(clsid); | |
} | |
else | |
{ | |
Console.WriteLine(" No CLSID value found for " + keyName); | |
} | |
} | |
} | |
} | |
} | |
private static string GetClsid(RegistryKey baseKey, string keyName) | |
{ | |
using (RegistryKey clsidKey = baseKey.OpenSubKey(keyName + @"\CLSID")) | |
{ | |
if (clsidKey != null) | |
{ | |
return (string)clsidKey.GetValue(""); | |
} | |
return null; | |
} | |
} | |
private static void CheckRegistryPathsForClsid(string clsid) | |
{ | |
string[] registryPaths = | |
{ | |
@"WOW6432Node\CLSID\", | |
@"CLSID\" | |
}; | |
const string subKey = @"\InprocServer32"; | |
foreach (var registryPath in registryPaths) | |
{ | |
string InprocKey = registryPath + clsid + subKey; | |
using (RegistryKey key = Registry.ClassesRoot.OpenSubKey(InprocKey)) | |
{ | |
if (key != null) | |
{ | |
string dllPath = (string)key.GetValue(""); | |
if (!string.IsNullOrEmpty(dllPath)) | |
{ | |
Console.WriteLine($" HKEY_CLASSES_ROOT\\{InprocKey}"); | |
Console.WriteLine($" \"{dllPath}\""); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment