tags:

views:

202

answers:

4

I've read about getting it with the Environment class, but can't find it.

Thanks guys.

A: 

A little Googling points here:

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

Hope that helps.

hehewaffles
A: 

Look here for an example. You will have to use P/Invoke.

n535
A: 

I'm thinking this could have been what you read:

System.Environment.GetEnvironmentVariable("USERDOMAIN")

But this has nothing to do with workgroup name. The workgroup name is not available in the environment (you could type "set" in a command prompt to verify that).

Jakob Kruse
+1  A: 

You can do this with WMI; add a reference to System.Management.dll and a using statement for System.Management namespace, then call the following code:

ManagementObjectSearcher mos = 
  new ManagementObjectSearcher(@"root\CIMV2", @"SELECT * FROM Win32_ComputerSystem");
foreach (ManagementObject mo in mos.Get()) {
  Console.WriteLine(mo["Workgroup"]);
}
Jono
Thanks for the edit, Hans. At first it had the escaped backslash, then I edited it to make them verbatim strings but the syntax highlighting disappeared. When I changed it back (I like seeing my code in color,) I didn't get it quite right. Still no highlighting though, I see?
Jono