O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Retrieve a List of All Windows Accounts or Groups

Problem

You need to retrieve a list of all users on the current computer or on a network domain.

Solution

Perform a query using the Win32_UserAccount or Win32_Group Windows Management Instrumentation (WMI) class.

Discussion

The Microsoft .NET Framework doesn’t include any classes that allow you to retrieve a list of Windows accounts. However, there’s no need to delve into the intricacies of the Win32 API—instead, you can access this information by performing a simple WMI query.

To use the WMI objects, you must import the System.Management namespace and add a reference to the System.Management.dll assembly. You can then retrieve a list of users by domain, by computer name, or by using a combination of ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required