Get the MACHINE domain, not the user domain.

  • Thread starter Thread starter SiPearson
  • Start date Start date
S

SiPearson

Hi,

I'm writing an app that needs to get the domain the machine running it
belongs to. I know that you can do a Environment.UserDomainName, but
this returns the domain the user has logged onto.

What I have is a machine that sits on a resource domain called ***Res,
and a trusted domain the user logs onto the machine called Global.
The user always logs onto Global, but the machine could be on BobRes,
BillRes or BrianRes.

I'd be grateful if someone could help me found out which domain the
machine is on.

Many thanks

Simon
 
You have some options, in order of preference:

- Use the System.Management namespace classes.
- Use the System.DirectoryServices and the NT4 ADSI provider interface
- Use PInvoke

Here's a sample using the first:

....
ManagementObject cs;
using(cs = new ManagementObject
("Win32_ComputerSystem.Name='yourSystemName'" ))
{
cs.Get();
Console.WriteLine("{0}",cs["domain"].ToString());
}
}
...

Willy.
 
Hi simon

Thank you for posting in the community!

Based on my understanding, you want to get the domain's name which your
machine belongs to, but not the domain your user logon.

=================================================
Just as Willy suggested, you can use System.Management classes to work for
you.

Actually, System.Management classes use WMI to get the system information.

I have tested Willy's sample, it works well.

For more information about Win32_ComputerSystem structure, please refer to:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/
win32_computersystem.asp

=================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Many thanks to both of you for your help, thats exactly what I was looking for.

Thanks again

Simon
 
Hi simon

Thanks for your feedback.

If you have any further concern, please feel free to tell me, I will work
with you. thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top