Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

This resource has not currently been approved, and is not currently linked to from our directory of resources. It is being displayed here for preview by the author and moderators only.
Rated
Read 1,068 times

Downloads

Related Categories

Printing all Available Users - Explanation and Code

pcmattman

Explanation and Code

The EnumUsers function loops through each user available on the system by using the Net functions. Once data has been recieved, it is converted into a multibyte string and printed to the console. After it has been printed, the next user is grabbed and the loop restarts. Once the loop fails, the function ends with no return value.

#include <windows.h>
#include <lmaccess.h>
#include <iostream>

#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;
}


(blanked out for safety)

I began programming in 2002, where I first learnt Python. I then went on to learn VB. By 2005, I had learnt and used C++, C#, PHP, HTML, and many other scripting languages for games and programs. I was pleased to find this website in 2006 and am now looking for more advanced tutorials. I have now taken on operating system development and for the first four months of 2007 was coding for hours each day. Still a work in progress, but you can download test releases at http://www.sourceforge.net/projects/mattise I'm still heavily involved in operating system development, and am now branching out to artificial intelligence, namely neural networks and 'learning' AI.

Comments