By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,534 Members | 910 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,534 IT Pros & Developers. It's quick & easy.

Get Domain/Workgroup name of PC Registration

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
On Wed, 14 Jul 2004 16:44:12 +0200, Mark Hollander <ma**@atcom.co.za> wrote:

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 ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 20 '05 #2

P: n/a
You can use WMI as well...

Dim computer as New WMISample.ROOT.CIMV2.ComputerSystem

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

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

Telmo Sampaio

"Mark Hollander" <ma**@atcom.co.za> wrote in message
news:si********************************@4ax.com...
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

Nov 20 '05 #3

P: n/a
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #4

P: n/a
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #5

P: n/a
On Thu, 15 Jul 2004 01:10:09 -0700, Mark Hollander <ma**@atcom.co.za> wrote:

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 ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 20 '05 #6

P: n/a
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
"Paul Clement" <Us***********************@swspectrum.com> wrote in message
news:rp********************************@4ax.com...
On Thu, 15 Jul 2004 01:10:09 -0700, Mark Hollander <ma**@atcom.co.za> wrote:
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 ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)

Nov 20 '05 #7

P: n/a
Imports System.Management - add a reference to this too.

(VD.NET??? Is that next version of AIDS?? :D)
_____________________________
The Grim Reaper

"Mark Hollander" <ma**@atcom.co.za> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #8

P: n/a
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #9

P: n/a
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #10

P: n/a
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

"Mark Hollander" <ma**@atcom.co.za> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #11

P: n/a
On Thu, 15 Jul 2004 23:30:15 -0700, Mark Hollander <ma**@atcom.co.za> wrote:

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 ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 20 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.