How to verify that "DLL" files was successfully registered

Asked

Viewed 2,095 times

0

I need to check if the process has been run successfully, 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 will I check whether files from that extension have been successfully registered?

  • 1

    Just out of curiosity, why does someone need a registered DLL in modern Oses, instead of simply charging? Something else. and if the extension is one of the variants such as .Exe, or .eXe, for example? Wouldn’t be the case to compare case insensitive?

  • No, because it is an internal system of the company, where you need to register the DLL for another system to understand and run, the . EXE I used the check to ignore these extension

1 answer

1


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

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

But for that you need to know the Guid, and probably you don’t know. So the solution is to read the subkeys of the CLSID and search 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;
}
  • This almost there, but gave me a light, thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.