hi everyone. I have written a code to enumerate all user list but
problem 1:
it is displaying names of active users only on local system. but when i take remote of other system and run my code it retrieves nothing.whereas i want the list of all users including active users,disconnected users,console users
problem 2:
i also want to display the states of user (like active,disconnected,console).
how do i acheive this can any one help?
#include "stdafx.h"
#ifndef _WIN32_WINNT // Allow use of features specific to Windows X or later.
#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.
#endif
#include <windows.h>
#include <WtsApi32.h>
#include <tchar.h>
#pragma comment(lib, "WtsApi32.lib")
int _tmain(int argc, TCHAR** argv)
{
LPTSTR szUserName = NULL;
LPTSTR szDomainName = NULL;
DWORD dwLen = 0;
BOOL bStatus = WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE,
WTS_CURRENT_SESSION,
WTSDomainName,
&szDomainName,
&dwLen);
if (bStatus)
{
bStatus = WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE,
WTS_CURRENT_SESSION,
WTSUserName,
&szUserName,
&dwLen);
if (bStatus)
{
DWORD cbUpn = _tcslen(szUserName) + 1 + _tcslen(szDomainName);
LPTSTR szUpn = (LPTSTR)LocalAlloc(0, (cbUpn + 1) * sizeof(TCHAR));
_tprintf(_T("UPN = %s\n"), szUserName);
LocalFree(szUpn);
WTSFreeMemory(szUserName);
}
else
{
_tprintf(_T("WTSQuerySessionInformation on WTSUserName failed with error 0x%.8X\n"), GetLastError());
}
WTSFreeMemory(szDomainName);
}
else
{
_tprintf(_T("WTSQuerySessionInformation on WTSDomainName failed with error 0x%.8X\n"), GetLastError());
}
return 0;
}