When I try to compile the code (showed below) I get those 2 errors:
- reference to the external simbol _WTSQuerySessionInformationW@20 not solved in the function void_cdecl Test(void)" (?Test@@YAXXZ);
- reference to the external simbol _WTSFreeMemory@20 not solved in the function void_cdecl Test(void)" (?Test@@YAXXZ)
The purpose was to output the name of the username logged on windows and the username who ran the program, but I got those 2 mistakes while compiling.
#include <iostream>
#include <Windows.h>
#include <wtsapi32.h>
#include <Lmcons.h>
void Test()
{
WCHAR UsernameSSR[UNLEN + 1];
DWORD bufCharCountSSR = UNLEN + 1;
if (GetUserNameW(UsernameSSR, &bufCharCountSSR))
std::wcout << L"UsernameSSR: " << UsernameSSR << std::endl;
else
std::wcout << L"Error getting UserNameSSR" << std::endl;
LPWSTR UsernameWindows;
DWORD bufByteCountWindows;
if (WTSQuerySessionInformationW(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSUserName, &UsernameWindows, &bufByteCountWindows))
{
LPWSTR Domain;
DWORD bufByteCountDomain;
std::wcout << L"UsernameWindows: ";
if (WTSQuerySessionInformationW(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSDomainName, &Domain, &bufByteCountDomain))
{
if (*Domain)
std::wcout << Domain << L"\\";
WTSFreeMemory(Domain);
}
std::wcout << UsernameWindows << std::endl;
WTSFreeMemory(UsernameWindows);
}
else
std::wcout << L"Error getting UserNameWindows" << std::endl;
}
int main() {
Test();
return 0;
}