GetObject throws Error

T

Tam

Hi, I keep getting ActiveX can't create object : GetObject when using the
below code. I registered the form as a fully trusted form using regform
utility...but still it gives me an error on GetObject Function. There is a
CreateObject Method also used in the code which doesn't give me any error.
Below is the code ...

Sub XDocument_OnLoad(eventObj)
Set Ref =
XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:Test_Plan/@NT_User_Name")
Ref.text = NTUserName()
End Sub

Public Function NTUserName()
strComputer = "."
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colCSItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
For Each objCSItem In colCSItems
UserName = objCSItem.UserName
Next
Set objWMIService = Nothing
Set colCSItems = Nothing
NTUserName = UserName
End Function

I have been trying to fix this issue for a long time no success.. would
appreciate help in this case.
 
S

S.Y.M. Wong-A-Ton

Are you testing the form in Preview mode? If so, try testing it from where
you registered it. Or save the form template on disk, go to the location
where you saved it, double-click it, and test it from there. GetObject cannot
be tested in Preview mode, since the form cannot acquire the full trust it
needs.
 
T

Tam

Hi Wong,
Appreciate ur reply, yes you are right in saying in preview it
doesn't work. On my local system I am able to get the NT ID with getObject
method, but on network i.e. when I am trying to access the form from the
network it doesn't give pull in the NT ID. Is there anything that I am
missing..?? No getObject Error on Local or Network.

Thanks Tam.
 
S

S.Y.M. Wong-A-Ton

I don't know much about WMI scripting, but logic tells me that you cannot run
code from a network location to retrieve settings on a local computer, since
it would breach security.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top