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 10 Network
Windows 10 Network
Windows 10: A Microsoft operating system that runs on personal computers and tablets.Network: A group of devices that communicate either wirelessly or via a physical connection.
2,363 questions
0 comments No comments
{count} votes

Your answer

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