0

I have one doubt , WTSQueryUserToken() is an inbuilt function . This function not working Not compiled successfully

#include <wtsapi32.h>

ULONG sessionID = (ULONG)WTSGetActiveConsoleSessionId();
printf("\n\t\t%ld", sessionID);  // 1 because I'm first user
HANDLE hToken = 0;
int pToken = WTSQueryUserToken((ULONG)sessionID, (PHANDLE)&hToken);
if (pToken == 0)
{
    puts("\n\tWTSQueryUserToken() fails");
    printf("\n\tError No\t: %d\n", GetLastError());
    CloseHandle(hToken);
    return;
}
else
    puts("\n\tWTSQueryUserToken() Success - Got primary access token");

Here I'm getting error as LNK2019 : unresolved external symbol WTSQueryUserToken referenced in function main LNK1120 : 1 unresolved externals

Its user defined function then how it'll become external symbol error I'm not able to run this code in VisualStudio 2019 in C or C++.

  • It looks like linking `Wtsapi32.lib` is requied. [WTSQueryUserToken function (wtsapi32.h) - Win32 apps | Microsoft Docs](https://docs.microsoft.com/en-us/windows/win32/api/wtsapi32/nf-wtsapi32-wtsqueryusertoken) – MikeCAT Jul 29 '21 at 14:45

0 Answers0