How to check if the "DLL" files were successfully registered

0

I need to check if the process has been successful, in case the extensions it will try to register are:

  • .DLL
  • .OCX

The code I'm using to register is this:

string pathcli = copiar + nomedofonte;

if (!nomedofonte.Contains(".exe") ||!nomedofonte.Contains(".EXE"))
{                        
    Process proc = new Process
    {
        StartInfo =
        {
            FileName = Registrador,
            Arguments = "/s"+pathcli,
            RedirectStandardError = true,
            UseShellExecute = false,
            CreateNoWindow = true
         }
     };

    proc.Start();
    Application.DoEvents();
}

How do I check if the files for that extension have been successfully registered?

    
asked by anonymous 23.01.2018 / 16:13

1 answer

1

You can inspect the Windows registry to see if DLL or OCX is registered. The CLSID node has the registered keys:

HKEY_CLASSES_ROOT\CLSID\{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}

But for this you need to know Guid , and probably you do not know. So the solution is to read the CLSID subkeys and look for the name of DLL or OCX , as in the example below:

bool VerificarRegistro(string nomeDLL)
{
    bool achou = false;
    RegistryKey clsid = Registry.ClassesRoot.OpenSubKey("CLSID");
    string[] ClsIDs = clsid.GetSubKeyNames();
    string subkey = "";
    for (int i = 0; i < ClsIDs.Length; i++)
    {
        subkey = ClsIDs[i];
        if (subkey.Substring(0, 1) != "{") continue;
        RegistryKey cls = Registry.ClassesRoot.OpenSubKey("CLSID\" + subkey + "\InprocServer32");
        if (cls == null) continue;
        string x = cls.GetValue("", "").ToString();
        if (x.IndexOf(nomeDLL) >= 0)
        {
            achou = true;
            break;
        }
    }
    return achou;
}
    
23.01.2018 / 17:06