C# - Get workgroup name

johnb2201 0 Reputation points
2024-07-12T00:36:22.52+00:00

Using Visual Studio 2010 - C#

I want to get the computers workgroup name.

I tried both of these on Windows XP:

string workgroupName = Environment.GetEnvironmentVariable("UserDomainName");

string workgroupName = (string)Registry.GetValue(key1, "Workgroup", null);

The first gives me the computer name.

The second is blank.

Please suggest a solution that will work on all versions of Windows.

Windows for business | Windows Client for IT Pros | Networking | Network connectivity and file sharing
0 comments No comments
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.