System.Runtime.InteropServices.COMException

G

Guest

i have an application in VB .NET. I am trying to get UserName and Domain from
my Computer using the following code and it was working properly until i
reinstalled Visual Studio .NET (i had an other problem). I am not sure tha
this action generated the problem, but i don't know what to check to see what
is the problem.

'--------------------------------------------------------------------------
Dim results As clsWMIDomainUsers = New clsWMIDomainUsers

Dim srchr As ManagementObjectSearcher = New ManagementObjectSearcher("SELECT
* FROM Win32_ComputerSystem")
Dim coll As ManagementObjectCollection
Dim mo As ManagementObject

coll = srchr.Get

For Each mo In coll

results.FullyQualifiedUserName = CStr(mo.Item("UserName"))
results.DefaultDomainController = CStr(mo.Item("Domain"))
SplitDomainAndUserName(results)
Exit For
Next

'-------------------------------------------------------------------
When the "For Each mo In coll" is executing the following error is generate
"A first chance exception of type
'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll" and
nothing else...

Any help please???
 
P

Pete Wright

I'm not an interop guy so can't answer that question, BUT, are you aware
that there are .NET namespaces that provide an alternative way to get this
information without getting mucky in Interop?

System.Environment.UserDomainName
System.Environment.UserName


Hope that helps,
 
G

Guest

What i really want to do is to find out which domain current user belongs to
and get all users of it.The only way doing this (getting all domain users)is
using "Active Directory" (my block of code) .So, even if i use
System.Environment.UserDomainName to get Domain name , i will have the same
problem when i use WMI to get all domain users.

As far as my problem concerns, i found out that one system file (WMI...i
dont remember the rest of its name, sorry) was corrupted. I reinstaled
Windows XP (i had some other problems to) and the problem seems to be solved

Anyway, Thank you for the response.
 

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