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
.
You can get a free domain through a variety of ways, either by getting a web hosting plan, a site builder, an email hosting plan, or through a free domain registrar.
For countries where Google Domains is available, you can use Google Domains to purchase a domain. By default, Google Domains provides a one-year registration period and opts you in to auto-renew (step 6 below).
To check if a domain name is available, just type it in GoDaddy's search bar and we'll tell you immediately if someone else already owns it. If it's taken, you can search for your desired domain name using our WHOIS Lookup.
Why are you using WMI? Can't you use the standard .NET functionality?
System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With