Find a match in connection values

I am having problems with the following two points:

  • How to get all subkey values ​​in ClassesRoot \ Typelib and;
  • How to find a match for a known value (pathname / dll) in the subkey values ​​array.

As a reference, I'm trying to find a way to check if a DLL has been registered. Someone said that checking the ClassesRoot \ Typelib for a DLL was one way to do it, since I know the directory location and the DLL name, but nothing else.

Does anyone have any tips? Greetings.

+1


source to share


2 answers


I haven't tested it extensively and it has very little error handling code, but it should get you started.

public static bool IsRegistered(string name, string dllPath)
{
    RegistryKey typeLibKey = Registry.ClassesRoot.OpenSubKey("TypeLib");
    foreach (string libIdKeyName in typeLibKey.GetSubKeyNames())
    {
        RegistryKey libIdKey = typeLibKey.OpenSubKey(libIdKeyName);
        foreach (string versionKeyName in libIdKey.GetSubKeyNames())
        {
            RegistryKey versionKey = libIdKey.OpenSubKey(versionKeyName);
            string regName = (string)versionKey.GetValue("");
            if (regName == name)
            {
                foreach (string itterKeyName in versionKey.GetSubKeyNames())
                {
                    int throwawayint;
                    if (int.TryParse(itterKeyName, out throwawayint))
                    {
                        RegistryKey itterKey = versionKey.OpenSubKey(itterKeyName);
                        string regDllPath = (string)itterKey.OpenSubKey("win32").GetValue("");
                        if (regDllPath == dllPath)
                        {
                            return true;
                        }
                    }
                }
            }
        }
    }

    return false;
}

      



}

+2


source


Take a look at Microsoft.Win32.Registry and Microsoft.Win32.RegistryKey.



public void Foo()
{
   foreach (string s in Microsoft.Win32.Registry.CurrentUser.GetSubKeyNames())
   {
      Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(s);
      // check here for the dll value and exit if found
      // recurse down the tree...
   }
}

      

+1


source







All Articles