Retrieving The COM Class Factory for Component with CLSID

Kailash Chandra Behera | Monday, August 24, 2020

Introduction

Recently I was working on a project where I have taken the reference to a couple of com objects and an unmanaged library. Suddenly I got the following error when I installed my project in a new windows machine.

Retrieving the COM class factory for component with CLSID {5630BE5A-3F5F-4BCA-A511-AD6A6386CAC1} failed due to the following error:
80040154 Class MagickImage not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

The main object of this blog is to find the com component library name or unmanaged library name using the VBScript code and resolve the error.

Getting Started

Basically, there are two cases for this error.

  1. If your com component or unmanaged library is not installed or not registered or corrupted in the system.
  2. When 32-bit com components or unmanaged libraries are used in a 64-bit system or vice versa.
Solutions:-

The solution to this error is, first you have to identify the com component or unmanaged library then take appropriate action based on the above case. The following code identities and gives the name of that com component or library. Copy the below code and paste it in a notepad file. Save the notepad file with extension .vbs

 Sub Main  
   ' used to find location of "System.Collections.ArrayList" progid dll  
   Const csGUID = "{5630BE5A-3F5F-4BCA-A511-AD6A6386CAC1}"  
   MsgBox srGetDllPathByGUID(csGUID)  
 End Sub  
 Function srGetDllPathByGUID( sGUID )  
   Const csRegPath = "HKEY_CLASSES_ROOT\CLSID\<GUID>\InProcServer32\"  
   Dim oShell: Set oShell = CreateObject("WScript.Shell")  
   Dim sReg: sReg = Replace( csRegPath, "<GUID>", sGUID ) ' build str  
   srGetDllPathByGUID = oShell.RegRead(sReg)  
   Set oShell = Nothing ' clean up  
 End Function  
 Call Main  

Find the CLSID (5630BE5A-3F5F-4BCA-A511-AD6A6386CAC1), replace it with the CLSID code you are getting in error, and save it again. Double click on the VBScript file, this will give you the name of the com component library in the message box if it is already registered.

If the message box is not showing the library name then that means you are facing the first case and your component is either corrupted or not installed. You have to reinstall the component or register it.

Retrieving The COM Class Factory for Component with CLSID

Retrieving The COM Class Factory for Component with CLSID

If you are getting the name of the library in the message box then that means your component is not registered in the machine. In the below, I have mentioned the solutions for each case.

Case -1:If your com component or unmanaged library is not installed or not registered or corrupted in the system.

If the com component is not installed in your machine or corrupted then install it or if it is not registered then register the library using the below line command. Open the command prompt with administrator rights and use below command to register.

 regsvr32 "C:\TFS\Code\bin\MailObj.dll"  

The regsvr32 takes the path of the library as a parameter. Replace the path (“C:\TFS\Code\bin\MailObj.dll”) with your library path, for example if your library is in D:\ Drive then the will be “D:\nameoflibrary.dll

Case-3: When 32 bit com components or unmanaged libraries are used in a 64 bit system or vice versa.

If you're getting the name of the library in the message box of a VBScript file then it is sure that there is a conflict between 64-bit process and 32-bit process.

The 64-bit process is trying to invoke a 32-bit process in a 64-bit machine that will look for the registry entry in HKLM\CLSID, HKCR\CLSID, or vice versa.

The solution is we have to force the 64-bit process to look at the registry entry at HKLM\Wow6432Node\CLSID and HKCR\Wow6432Node\CLSID or 32-bit process to look at HKLM\CLSID, HKCR\CLSID.

The simple solution for this case is either to use the appropriate library or change your platform target while building the project.

To change the platform target use the below steps.
  1. Right-click on your project name.
  2. Click on the property.
  3. Go to the Build tab.
  4. Find the platform target dropdown and select the required one(86x for 32-bit platform or 64 bit)
  5. Now you are done with changes and building your project.

Summary

In the above, we saw how to retrieve the com class factory for component with CLSIDusing VBScript and how to solve the error of com components missing. I hope you have enjoyed it a lot

Thanks