Hi,
I have been trying to get the currently logged-in user's token information using the following code :
[DllImport("wtsapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool WTSQueryUserToken(int sessionId, out IntPtr tokenHandle);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern uint WTSGetActiveConsoleSessionId();
static void Main(string[] args)
{
try
{
int sessionID = (int)WTSGetActiveConsoleSessionId();
if (sessionID != -1)
{
System.IntPtr currentToken = IntPtr.Zero;
bool bRet = WTSQueryUserToken(sessionID, out currentToken);
Console.WriteLine("bRet : " + bRet.ToString());
}
}
catch (Exception)
{
}
}
The problem is that, bRet is always false and currentToken is always 0.
I am getting the sessionid as 1.
Could someone tell me what's going wrong here?
I want to use this token information to pass it to the CreateProcessAsUser function from a windows service.
Thanks,
Ram