Get Domain/Workgroup name of PC Registration

  • Thread starter Thread starter Mark Hollander
  • Start date Start date
M

Mark Hollander

How do I get the name of the Workgroup or Domain that the computer has
been registered in.



Thank you
Mark Hollander



Thank you
Mark Hollander
 
¤ How do I get the name of the Workgroup or Domain that the computer has
¤ been registered in.
¤

The following uses ADSI:

Dim SystemInfo As Object

SystemInfo = CreateObject("ADSystemInfo")
Console.WriteLine(SystemInfo.DomainShortName)


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
You can use WMI as well...

Dim computer as New WMISample.ROOT.CIMV2.ComputerSystem

computer.path =
System.Management.ManagementPath("MyComp\root\CIMV2:Win32_ComputerSystem.Nam
e=""MyComp""")

Messagebox.Show(computer.Domain) //Shows Domain name or Workgroup name)

Telmo Sampaio
 
The problem is that I cannot use these 2 examples on a
Windows98/WindowsME machine.

Is there any other way I can get the Workgroup/Domain name

Thank You
Mark Hollander
 
I can't seem to get the WMI to work in VD.NET, what am i supposed to
include in the references to access the WMI.

Thank You
Mark Hollander
 
¤ The problem is that I cannot use these 2 examples on a
¤ Windows98/WindowsME machine.
¤
¤ Is there any other way I can get the Workgroup/Domain name
¤

How about the following:

Environment.UserDomainName()


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Paul,

Sometimes I am blinded by the simplicity of things... I have to agree that
using the Environment class is a lot easier than dealing with WMI.

Thanks,

Telmo
 
Imports System.Management - add a reference to this too.

(VD.NET??? Is that next version of AIDS?? :D)
_____________________________
The Grim Reaper
 
The problem with this function is that it returns the domain name that
the user logged onto.

Scenario

Computer is registered in DomainA
User is registered in DomainB

I want the DomainA name but I get DomainB as the domain name when I use
System.Environment.UserDomainName.

It is important that I get DomainA


Thank You
Mark Hollander
 
Did that but I cannot seem to access the following:
Dim computer as New WMISample.ROOT.CIMV2.ComputerSystem

The MSDN is vague on how to access this as I cannot seem to find
anything relating to it.

Thank You
Mark Hollander
 
Mark,

It took me a while to get the hang of the WMI stuff - and I still can't get
"complex" queries to work properly. See how you get on with this example;

Dim vQuery As New ManagementObjectSearcher("SELECT * FROM
Win32_ComputerSystem")
For Each vComputer As ManagementObject In vQuery.Get ' In case there's more
than one computer :))
' List all properties of Win32_ComputerSystem
For Each vProperty As PropertyData In vComputer.Properties
Console.WriteLine(vProperty.Name)
Next
' Print a random property
Console.WriteLine("Domain is: " & vComputer("Domain").ToString)
Next
________________________
The Grim Reaper
 
¤ The problem with this function is that it returns the domain name that
¤ the user logged onto.
¤
¤ Scenario
¤
¤ Computer is registered in DomainA
¤ User is registered in DomainB
¤
¤ I want the DomainA name but I get DomainB as the domain name when I use
¤ System.Environment.UserDomainName.
¤
¤ It is important that I get DomainA

I can't test this in a multiple domain environment but see if the following works for you:

Dim WMIComputerSystem As New System.Management.ManagementObjectSearcher("select * from
Win32_ComputerSystem")

Dim WMIInfo As System.Management.ManagementObject

For Each WMIInfo In WMIComputerSystem.Get
Console.WriteLine(WMIInfo("Domain").ToString)
Next WMIInfo


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Back
Top