views:

691

answers:

4

There gotta be an easy way to do this, I can't believe there's none. I have scanned through net and found, like, 20 different methods to find in which domain current user is, but none to get domain (or workgroup) of current machine.

In unmanaged c++ this is retrieved by:

WKSTA_INFO_100 *buf;
NetWkstaGetInfo(NULL, 100, (LPBYTE*)buf);
domain_name = pBuf->wki100_langroup;

can someone help me, if there's a way to get same info in managed C# natively?

EDIT1: Folks, please read the question. I am NOT looking for user domain name.

A: 

System.Environment.UserDomainName

bendewey
+8  A: 

To get the current domain of the system on which your progam is running you can use System.DirectoryServices.ActiveDirectory.Domain.

Domain domain = Domain.GetCurrentDomain();
Console.WriteLine( domain.Name );
tvanfosson
Oh, nice! Thanks, this is exactly what i was looking for!
galets
+1  A: 

Check out this website:

http://forums.devx.com/showthread.php?t=145593

you can take that class and make a dll file out of it, and use it in your program.

cheers

Souhail

Souhail
+1  A: 

If you don't want to add a dependency to System.DirectoryServices, you can also call the NetGetJoinInformation API directly.

David