Cannot create ActiveX component Error

aeskan

Well-known member
Joined
Aug 10, 2011
Messages
63
Programming Experience
3-5
Hi everybody,

I'm not sure this post belongs to this section, if so I would apologize.

I'm trying to get the computer description by computer name. The problem is; I get this error "Cannot create ActiveX component" when the following codes run, while the variable ComputerName sets to another computer name in the network except the local computer that the code is running in it.

Dim Obj As Object = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & ComputerName & "\root\cimv2").ExecQuery("Select * FROM Win32_OperatingSystem")
For Each obj1 In Obj
ComputerDesc = obj1.description()
Next

When the ComputerName is the local computer name everything is fine, but when I use another computer name in my network an error occures in the line "Dim Obj as Object = GetObject(...", as Cannot create ActiveX component!

Appreciate any suggestion or help beforehand.
 
John,

Surely it's an extremely useful tool. It generated codes below.

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem",,48)
For Each objItem in colItems
Wscript.Echo "-----------------------------------"
Wscript.Echo "Win32_OperatingSystem instance"
Wscript.Echo "-----------------------------------"
Wscript.Echo "Description: " & objItem.Description
Next

But when I use (strComputer = "RemoteComputerName") and execute the code it says: Microsoft VBScript runtime error: Permission denied: 'GetObject'

It's almost similar to my own code. Did you pay proper attention to my codes? I think the problem is somewhere else other than code!
 
That is still scripting. You have to change Code Language from Visual Basic Script (vbs) to Visual Basic .Net. Check out the app menus.
For remote computer there is also choice in Target Computer menu.
 
Thank you anyway John for WMI Code Creator, it was useful.

But in my case, the problem was a bunch of permissions in Group Policy, WMI Policy, Windows Firewall, DCOM port range configuration and some Windows services that must run for remote computer mananging. After error: "Cannot create ActiveX component", step by step I got "Permission Denied", "RPC server is unavailable" errors and etc, which guided me to the mentioned local area network configurations. So far I dismissed the case until have a time to consider it again.

Thanks.
 
Back
Top