#include #include #include #pragma comment( lib, "netapi32.lib" ) using namespace std; // EnumUsers: enumerates the users that may use this system void EnumUsers() { // variables NET_DISPLAY_USER* ndu; DWORD entRead; int maxForLoop = 0; int err; char buff[80]; // print info cout << "Enumerating users..." << endl; // enumerate the users // initialize err to get the data err = NetQueryDisplayInformation( NULL, 1, 0, 500, sizeof( NET_DISPLAY_USER ), &entRead, (PVOID*) &ndu ); while( err == ERROR_MORE_DATA ) { // convert the name to a multibyte string wcstombs( buff, ndu->usri1_name, GNLEN ); // output it cout << buff << endl; // set error to the return value of the function err = NetQueryDisplayInformation( NULL, 1, ndu->usri1_next_index, 500, sizeof( NET_DISPLAY_USER ), &entRead, (PVOID*) &ndu ); } } int main() { EnumUsers(); return 0; }