none
How to check if a Computer is connected to Domain or only a local Network? RRS feed

Answers

All replies

  • Isnt this possible?
    Best regards,
    Yavuz B.

    My Sharepoint and Enterprise 2.0 Blog http://www.starcoder.net
    Microsoft Sharepoint Resources & Blogs List
    Thursday, October 28, 2010 2:54 PM
  • The below code may generate an exception in a non domain based environment but you may want to give it a try to see if it returns the number of domain controllers. I'm in a domain based environment at the moment so I can't verify what will happen in a workgroup based environment.

        Dim DomainContext As New System.DirectoryServices.ActiveDirectory.DirectoryContext(System.DirectoryServices.ActiveDirectory.DirectoryContextType.Domain)
        Dim DomainObject As System.DirectoryServices.ActiveDirectory.Domain = System.DirectoryServices.ActiveDirectory.Domain.GetDomain(DomainContext)
        Console.WriteLine(DomainObject.DomainControllers.Count)
    
    


    Paul ~~~~ Microsoft MVP (Visual Basic)
    • Proposed as answer by Shahzad_Rafi Saturday, October 19, 2019 7:56 AM
    Thursday, October 28, 2010 4:03 PM
  • Hello Paul,

    i googled a little more around and found the following two WMI Queries:

     

    DomainRole

    PartOfDomain 

     

    Both found here: http://msdn.microsoft.com/en-us/library/aa394102(VS.85).aspx

     

    I will try this and give here a reply on this.


    Best regards,
    Yavuz B.

    My Sharepoint and Enterprise 2.0 Blog http://www.starcoder.net
    Microsoft Sharepoint Resources & Blogs List
    • Marked as answer by [Yavuz B.] Monday, November 1, 2010 8:48 AM
    Monday, November 1, 2010 8:36 AM
  • Both of the WMI Calls are working fine! Here a sample

     

        Dim query As New SelectQuery("Win32_ComputerSystem")
        Dim searcher As New ManagementObjectSearcher(query)
        Dim result As Boolean = False
        For Each mo As ManagementObject In searcher.[Get]()
          Console.WriteLine(mo("domainrole"))
        Next
    

     

    I have tried them under W7 and XP in an Domain and non Domain environment and everytime i get the correct result!


    Best regards,
    Yavuz B.

    My Sharepoint and Enterprise 2.0 Blog http://www.starcoder.net
    Microsoft Sharepoint Resources & Blogs List
    Monday, November 1, 2010 8:48 AM