Get Server Domain

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Using vbscript I can get the domain of a server by binging to the WinNT provider and then getting the ADsPath

Set comp = GetObject("WinNT://MyComputer"
sComputerAndDomain = comp.ADsPat

How do I do the same using c# and the .net framework

Thank
Richard Chown
 
Following code works for me

using System.DirectoryServices
...
DirectoryEntry entry = new DirectoryEntry("WinNT://Server03a")
string domain = entry.Parent.Name
Console.WriteLine(domain)
...

Note in general System.DirectoryServices does not provide access to all the ADSI functionality, so you may need to resort to adding a reference to the COM ADSI library (activeds.tlb) - then you will have access to the functionality you are familiar with

Richard
 
Thanks, works for me too. Exactly what I was looking for

----- richlm wrote: ----

Following code works for me

using System.DirectoryServices
..
DirectoryEntry entry = new DirectoryEntry("WinNT://Server03a")
string domain = entry.Parent.Name
Console.WriteLine(domain)
..

Note in general System.DirectoryServices does not provide access to all the ADSI functionality, so you may need to resort to adding a reference to the COM ADSI library (activeds.tlb) - then you will have access to the functionality you are familiar with

Richard
 
Back
Top