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.
DWORD res, i, er = 0, tr = 0, resume = 0;
LPCONNECTION_INFO_1 p,b;
LPTSTR lpszServer = NULL, lpszShare = NULL;
res=NetConnectionEnum(NULL, L"MySharedPrinter", 1, (LPBYTE *) &p, MAX_PREFERRED_LENGTH, (LPDWORD)&er, (LPDWORD)&tr,NULL);
if(res == 0)
{
if(er>0)
{
MessageBox(0,L"Got connections",0,0);
}
else
{
MessageBox(0,L"No connections",0,0);
}
}