could not create activex component

leontager

Well-known member
Joined
Jun 17, 2003
Messages
89
Hi, I am getting this error when I run my program. I do not have VB installed on this windows but it works fine on my other one. This is a fresh copy so I am pretty sure I am missing something. I am pretty sure the code that causes the crash is the following

Private Sub Terminate_All_IE()

Dim WMIObject As Object
Dim WMIObjectSet As Object

WMIObjectSet = GetObject("WinMgmts:").execquery("select * from Win32_process where name=IEXPLORE.EXE")
For Each WMIObject In WMIObjectSet
If WMIObject.Terminate = 0 Then
End If
Next
End Sub

It is suppose to close all IE windows but instead if gives me "Could not create an activex component"


Please help
 
you cant just use Objects that way ( if you turn on option strict you will see ) heres something basic i put together which closes all open IE windows...
Code:
        Dim typeShell As Type = Type.GetTypeFromProgID("Shell.Application")
        Dim objShell As Object = Activator.CreateInstance(typeShell)
        Dim o As Object = typeShell.InvokeMember("Windows", Reflection.BindingFlags.InvokeMethod, Nothing, objShell, Nothing)
        Dim obIe As Object
        For Each obIe In o
            obIe.GetType.InvokeMember("Quit", Reflection.BindingFlags.InvokeMethod, Nothing, obIe, Nothing)
        Next
hope it helps.
 
thanks for the code. I will try it instead of what i have. I am not sure what you meant by object strict.

thank you again.
 
Option Strict when switched to ON will give " Late Binding " errors if making incorrect casts / using Objects incorrectly. if you look at the Object property , you will see it only has GetType() after it , so typing Object.Name etc... will cause an error with Option Strict ON.
heres a link to an msdn article on it....Option Strict Statement
 
Hi, I seem to have a little problem with your code. When i have alot of instances of IE it only closes some of the windows. Some are left open for some reason. Is there anyway you could adjust it to close everything or suggest another way of doing it.

Thank you.
 
it works on lots of them here, but yes , much easier ...
Code:
        Dim prs As Process() = Process.GetProcessesByName("iexplore")
        Dim p As Process
        For Each p In prs
            p.CloseMainWindow()
        Next
:)
 
Back
Top