Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3341106
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:41:05+00:00 2026-05-18T00:41:05+00:00

My computer is in a Domain (Active Directory) and I need to get the

  • 0

My computer is in a Domain (Active Directory) and I need to get the domain name dynamically. I found the following code on the internet:

SelectQuery query = new SelectQuery("Win32_ComputerSystem");
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query))
{
    foreach (ManagementObject mo in searcher.Get())
    {
        if ((bool)mo["partofdomain"])
        {
            this.Domain = mo["domain"].ToString();
            break;
        }
    }
 }

It works exactly as I want and returns exactly the domain name as I want (when I am logged as Administrator). If the user is not a Domain Admin, I have an Access denied exception.

Does anybody know how to get the domain even with non-domain administrator users?

NOTE: I have found this solution on Internet System.Environment.UserDomainName; but it only gives me a part of the domain name.

I.e. my domain is: something.domain.com
and the UserDomainName returns only something.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:41:06+00:00Added an answer on May 18, 2026 at 12:41 am

    Why are you using WMI? Can’t you use the standard .NET functionality?

    System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to get the Windows domain name from Internet Explorer using classic asp
proxy.ClientCredentials.Windows.ClientCredential.UserName = user; proxy.ClientCredentials.Windows.ClientCredential.Password = password; proxy.ClientCredentials.Windows.ClientCredential.Domain = my computer's name; Hi! How can
I am new to Active Directory. I have a VBA Excel Add-In that should
Need your help with authenticating an active directory user ID against LDAP. My problem
I'm using C# to find my local computer's objectGuid by querying Active Directory. To
Given the code below using (var context = new PrincipalContext(ContextType.Domain, SOME_DOMAIN)) using (UserPrincipal userPrincipal
I would like to remove the domain/computer information from a login id in C#.
I have two Domain classes (Drives & Computer) class Computer { static hasMany =
Given a group like this in Active Directory: MainGroup GroupA User1 User2 GroupB User3
I'm using this code to readmy own event Log from my win7 Computer. EventLogQuery

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.