How to get the domain name |
How to get the domain name
|
How to get the domain name |
How to get the domain name |
How to get the current domain name?
Hi,
If anybody knows how to get the domain name(only domain name) of the system pls let me know. Thanks and Regards, Vinothkumar B bvinoth@tvsinfotech.com |
| |||
re: How to get the domain name
it is located in registry
in key HKLM/SOFTWARE/Microsoft/Windows NT/CurrentVersion/Winlogon/DefaultDomainName read this key and you have it Hope this helps Galin Iliev[MCSD.NET] www.galcho.com |
| |||
re: How to get the domain name
Console.WriteLine(Environment.UserDomainName);
None wrote:[color=blue] > Hi, > > If anybody knows how to get the domain name(only domain name) of the > system pls let me know. > > > Thanks and Regards, > Vinothkumar B > bvinoth@tvsinfotech.com >[/color] |
| |||
re: How to get the domain name
Hi,
This is giving me the username only not domain name. I want only the domain name. |
| |||
re: How to get the domain name"None" <vinkumrect@gmail.com> wrote in message news:1147675234.188206.42850@i40g2000cwc.googlegro ups.com... | Hi, | | This is giving me the username only not domain name. I want only the | domain name. | No, it's returning the domain name not the user name. Willy. |
| |||
re: How to get the domain name"Galcho[MCSD.NET]" <galcho@gmail.com> wrote in message news:1147673857.537214.260590@i40g2000cwc.googlegr oups.com... | it is located in registry | | in key | HKLM/SOFTWARE/Microsoft/Windows | NT/CurrentVersion/Winlogon/DefaultDomainName | | read this key and you have it | | Hope this helps | Galin Iliev[MCSD.NET] | www.galcho.com | Sure, almost all configuration parameters are stored in the registry, but you better use the appropriate API's to get this kind of info instead of reading directly from the registry. The reason is simple, their location is not documented and is not guaranteed to remain the same across OS versions, and the registry is subject to access privilege restrictions. Willy. |
| |||
re: How to get the domain name
You're right, Thanks for advise
I did not take a look at Environment class regards Galin Iliev[MCSD.NET] www.galcho.com |
| |||
re: How to get the domain name"jeremiah johnson" <naikrovek@gmail.com> wrote in message news:uqgNlc%23dGHA.3888@TK2MSFTNGP02.phx.gbl...[color=blue] > Console.WriteLine(Environment.UserDomainName); > > None wrote:[color=green] > > Hi, > > > > If anybody knows how to get the domain name(only domain name) of the > > system pls let me know. > >[/color][/color] .... However, there are two domain names involved: domain that computer belongs to and domain current logged user belongs to. Two may not be the same (in case there are domain trusts between domains). It is not clear what original poster wanted though. Regards, Goran |
| |||
re: How to get the domain name"Goran Sliskovic" <gsliskov@yahoo.com> wrote in message news:eWG0GDAeGHA.3888@TK2MSFTNGP04.phx.gbl... | | "jeremiah johnson" <naikrovek@gmail.com> wrote in message | news:uqgNlc%23dGHA.3888@TK2MSFTNGP02.phx.gbl... | > Console.WriteLine(Environment.UserDomainName); | > | > None wrote: | > > Hi, | > > | > > If anybody knows how to get the domain name(only domain name) of the | > > system pls let me know. | > > | ... | | However, there are two domain names involved: domain that computer belongs | to and domain current logged user belongs to. Two may not be the same (in | case there are domain trusts between domains). It is not clear what original | poster wanted though. | | Regards, | Goran | | That's right. To get Domain info it's better to use WMI or ADSI, both are accessible from .NET through the System.Management and System.DirectoryServices namespaces. To get the machine account domain for instance you can query the 'Win32_ComputerSystem' WMI class like this: SelectQuery query = new SelectQuery("Win32_ComputerSystem"); using(ManagementObjectSearcher searcher = new ManagementObjectSearcher(query)) { foreach (ManagementObject mo in searcher.Get()) { if((bool)mo["partofdomain"] != true) Console.WriteLine("Workgroup: {0} ",mo["workgroup"]); else Console.WriteLine("Domain: {0} ",mo["domain"]); } } To get the interactive logon account domain, you can query the Win32_LogonSession and it's associated Win32_Account instance. If all you need is to get the logon account domain from a program running in the logon session of an iteractive user, just read the Environment.UserDomainName property. In all other cases, that is, applications running in non interactive logon sessions, you cannot rely on the Environment class to get this kind of info, so you will need to use one of the above. Willy. |