Microsoft VBScript runtime error -ActiveX Component Can’t Create Object

VbScript Runtime error-ActiveX Component Can't Create Object
VbScript Runtime error-ActiveX Component Can’t Create Object

VbScript Runtime error-ActiveX Component Can’t Create Object:

Very recently I am facing this issue with one of the test machine. The DOS prompt says Microsoft VBScript runtime error: ActiveX component can’t create object.

Code generating VBScript Runtime Error:

Dim qtApp
Dim qtResultsOpt
Dim qtTestdir, resdir
Dim Shell

Set Shell = CreateObject("WScript.Shell")
qtTestdir =my test path
resdir ="my result path"
Set qtApp = CreateObject("QuickTest.Application")
If Not qtApp.Launched Then
End If
qtApp.Visible = True
qtApp.Options.Run.CaptureForTestResults = "OnError"
qtApp.Options.Run.RunMode = "Fast"
qtApp.Options.Run.ViewResults = False
qtApp.Open qtTestdir, True
Set qtTest = qtApp.Test
qtTest.Settings.Run.OnError = "NextStep"
Set qtResOpt = CreateObject("QuickTest.RunResultsOptions")
qtResOpt.ResultsLocation = resdir
qtTest.Run qtResOpt
Set qtResOpt = Nothing
Set qtTest = Nothing
Set qtApp = Nothing

it was throwing error on the line no=10 that is Set qtApp = CreateObject(“QuickTest.Application”). In the DOS prompt the error was pretty clear.

Solutions of VbScript Runtime error-ActiveX Component Can’t Create Object:

As usual , Google came all the way with bunch of suggestion distributed in different pages!!. I am just summarizing what I followed..

I just updated the code like

On Error Resume Next
Set qtApp = CreateObject("QuickTest.Application")
Msgbox Err.Number

But to my surprise, it did not work. Some asked to increase the time as wait between the execution

On Error Resume Next
WScript.Sleep 5*60000
Set qtApp = CreateObject("QuickTest.Application")
Msgbox Err.Number

Even that did not work.

See also  Learn How to Work with XML with UFT in Fast and Effortless Manner

Some more suitable solutions of VbScript Runtime error-ActiveX Component Can’t Create Object.

1. Restart machine
2. Disable firewall and check
3. This is due to timing issue of creating ActiveX component object,when it is taking more time to open QTP more time like-5 mins.It gives me error in the line “Set objQTP = CreateObject(“QuickTest.Application”)” itself, before coming to line objQTP.Launch.And after the error it closes the QTPro.exe and QTAutomationAgent.exe processes that has been created due to CreateObject method, and objQTP is becoming null.
4. if it is Windows Vista Client you need to install QTP correctly.

  • Enabling UAC
  • Installing as User
  • Start QTP as Admin first.

5. Re register the QTP server using the below command

  • For XP:
    “C:Program FilesHPQuickTest ProfessionalbinQTAutomationAgent.exe” /regserver 
  • For Windows Server
    “C:Program Files (x86 )HPQuickTest ProfessionalbinQTAutomationAgent.exe” /regserver 

Till now I had no success…what I thought that might be the QTP process had not been closed by the code. So I modified my code little bit..

Dim objWMIService, objProcess, colProcess
Dim strComputer, strProcessKill
strComputer = "."
strProcessKill = "'QTPro.exe'"

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\" _
& strComputer & "rootcimv2")

Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcessKill )
For Each objProcess in colProcess

I thought that it was the end of problem!!!

But to my bad luck, it did not work….Still I was getting ActiveX component can’t create object error.

One of friend said to re-register the VBScript.dll

1.Open Command prompt from Run
2.Type regsvr32 %SystemRoot%system32VBScript.dll
3.Click on Enter
This is how we should re-register the dll file. or register the WScript object by running the wscript -regserver command from a command prompt or from the Run command on the Start menu

I was not convinced with the solution as I was not getting any error code.Interestingly at this point I hadm noticed that QTPro.exe was actually in the task manager. So QTP was actually running in the backend but not coming in the front. Problem became very complex at that time.

See also  How to work with Reporter Object in QTP or UFT

Final Solution of VbScript Runtime error-ActiveX Component Can’t Create Object:

At this point of time an article published here,looked resolve my problem..

I recently helped someone who had the same problem, but with a VB Script application, executed with cscript.exe. This VB script application uses a 32-bit COM object and failed to run on a 64-bit OS. The error, Microsoft VBScript runtime error: ActiveX component can’t create object: ‘XXXXXX’.

To fix the issue, the script must be executed with the right executable. There are two cscript.exe in the 64-bit OSes. One is located at %WINDOWS%System32, and the second one is located at %WINDOWS%SysWOW64.

The one under System32, is a 64-bit version. The one under SysWOW64 is the 32-bit version. Run the VBS application using the 32-bit application.

Why System32 contains 64-bit binaries, and SysWOW64 contains 32-bit is another story, but there is a very good reason behind it, backward compatibility. 🙂

As I had no other choice, I tried to start QTP with this approach only. But !!!!! Still It was failing!!!!.

Suddenly I saw a pop up silently seating in the task bar. Very humble, it was saying there were 12 updates and needed restarts.Company policy needed to be updated.

I just allowed them to get installed..restarted 3 times…It worked like champ. VBS started wroking.

Share and Enjoy !

Leave a Reply

Your email address will not be published. Required fields are marked *