By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,169 Members | 1,417 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,169 IT Pros & Developers. It's quick & easy.

How to get the domain name

P: n/a
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
bv*****@tvsinfotech.com

May 15 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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

May 15 '06 #2

P: n/a
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.
Thanks and Regards,
Vinothkumar B
bv*****@tvsinfotech.com

May 15 '06 #3

P: n/a
Hi,

This is giving me the username only not domain name. I want only the
domain name.

May 15 '06 #4

P: n/a

"None" <vi********@gmail.com> wrote in message
news:11*********************@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.
May 15 '06 #5

P: n/a

"Galcho[MCSD.NET]" <ga****@gmail.com> wrote in message
news:11**********************@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.
May 15 '06 #6

P: n/a
You're right, Thanks for advise

I did not take a look at Environment class

regards

Galin Iliev[MCSD.NET]
www.galcho.com

May 15 '06 #7

P: n/a

"jeremiah johnson" <na*******@gmail.com> wrote in message
news:uq****************@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
May 15 '06 #8

P: n/a

"Goran Sliskovic" <gs******@yahoo.com> wrote in message
news:eW**************@TK2MSFTNGP04.phx.gbl...
|
| "jeremiah johnson" <na*******@gmail.com> wrote in message
| news:uq****************@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.

May 15 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.