Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to find out the connected clients to a shared resource (printer) on my server. The program will run on the server and will form a list of all the connected clients to the shared resource (or the local machine).

Is there any way that I can do it using WMI or otherwise in C# or c++?

Here is the code in c++ that I tried. The API succeeds but does not return the printer connections.

C++
DWORD res, i, er = 0, tr = 0, resume = 0;
LPCONNECTION_INFO_1 p,b;
LPTSTR lpszServer = NULL, lpszShare = NULL;
    
	 res=NetConnectionEnum(/*lpszServer*/NULL, L"MySharedPrinter", 1, (LPBYTE *) &p, MAX_PREFERRED_LENGTH, (LPDWORD)&er, (LPDWORD)&tr,/* &resume*/NULL);
	  if(res == 0)
	  {
		  if(er>0)
		  {
			MessageBox(0,L"Got connections",0,0);
		  }
		  else
		  {
			  MessageBox(0,L"No connections",0,0);
		  }
	  }
Posted

1 solution

 
Share this answer
 
Comments
kaushik_code 28-Jan-15 1:53am    
The above approaches are based on enumerating the sessions of a computer.Which is what we see in the Shared folder\Sessions snap-in in compmgmt.msc.
The problem is in a domain environment when a print client creates a connection with a print object on the print server, the session is not listed there and hence enumerating session does not help.
Zoltán Zörgő 28-Jan-15 13:08pm    
Print sessions are rather transient. Why do you need this?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900