none
Determine if dll is registered

    Question

  • Hi,
     
    I'm looking for a way to determine if a dll/exe/ocx is registered on the system (through regsvr32).

    I'm using VB.net and have been trying the code below; but it always return a library id from LoadLibrary function. If the file is on disk, then it returns true.
    How can I determine if a specific file is registered?

    Like if I have these files on disk:
      C:\myfile.ocx
      C:\temp\myfile.ocx

    How can I determine that the file in C:\temp\myfile.ocx is registered on the system?

    OS is Win XP Pro and framework is 3.5

    /Peter Haislund

    1         Private Declare Function LoadLibraryA Lib "kernel32.dll" (ByVal lpLibFileName As StringAs Integer 
    2         Private Declare Function FreeLibrary Lib "kernel32.dll" (ByVal lpLibFileName As StringAs Boolean 
    3  
    4         Private Sub ValidateRegistration()  
    5                 Dim proceed As Boolean = False 
    6  
    7                 If String.Compare(".dll"Me.Extension, True) = 0 Then 
    8                     proceed = True 
    9  
    10                 ElseIf String.Compare(".ocx"Me.Extension, True) = 0 Then 
    11                     proceed = True 
    12  
    13                 End If 
    14  
    15                 If proceed Then 
    16                     Dim tmpLibraryID As Integer = LoadLibraryA(Me.FullName)  
    17  
    18                     If tmpLibraryID > 0 Then FreeLibrary(tmpLibraryID)  
    19  
    20                     Me._IsRegistered = tmpLibraryID > 0  
    21  
    22                 End If 
    23  
    24         End Sub 
    Monday, February 16, 2009 9:26 AM

Answers

  • You cannot use LoadLibrary().  The only way to do this is to enumerate the registry keys in HKLM/Software/Classes/Clsid and HKCU/Software/Classes/Clsid and check if any of the GUIDs there has a InProcServer32 value that matches the path to the DLL.  Note that this still doesn't allow you to detect COM servers who get activated though registry-free COM registration with a manifest.  Quite common these days.

    Do not use Regsvr32.exe.  Registry redirection in Vista will make the component unusable.  Also beware of redirection to Wow6432Node in 64-bit Windows.  Hopefully I scared you out of doing this.

    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Friday, February 20, 2009 9:26 AM
    Monday, February 16, 2009 1:27 PM
    Moderator

All replies

  •  Unregister it.  If it was successful, it was registered.
    Monday, February 16, 2009 9:37 AM
  • That doesn't sound like a good way of doing it?

    What if the file is being used by another application or if re-registering it fails somehow?

    Also; If I call 'regsvr32 filename -u' on a file that supports registration, then it always says successfull even if the file wasn't registered. So from my point of view it seems that as long as the file has a valid entry point it is "succesfull".

    Any thoughts?
    Monday, February 16, 2009 10:02 AM
  • You cannot use LoadLibrary().  The only way to do this is to enumerate the registry keys in HKLM/Software/Classes/Clsid and HKCU/Software/Classes/Clsid and check if any of the GUIDs there has a InProcServer32 value that matches the path to the DLL.  Note that this still doesn't allow you to detect COM servers who get activated though registry-free COM registration with a manifest.  Quite common these days.

    Do not use Regsvr32.exe.  Registry redirection in Vista will make the component unusable.  Also beware of redirection to Wow6432Node in 64-bit Windows.  Hopefully I scared you out of doing this.

    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Friday, February 20, 2009 9:26 AM
    Monday, February 16, 2009 1:27 PM
    Moderator
  • How do you define "registered"? You usually don't know what the author of an ActiveX choose to write it in DllRegisterServer.
    MSMVP VC++
    Monday, February 16, 2009 9:46 PM
  • you can use this: My.Computer.Registry.ClassesRoot.GetSubKeyNames.Contains("gEncrypt.clsEncrypt") Where "gEncrypt.clsEncrypt" is ComName.ClassName.

    Is the simplest way to do that,.

    Wednesday, June 01, 2011 4:13 PM