Unable to get the Current User's Token information
<p>I have been trying to get the currently logged-in user's token information using the following code : </p>

<pre><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)
        {
        }
    }
</code></pre>

<p>The problem is that, bRet is always false and currentToken is always 0. 
I am getting the sessionid as 1.</p>

<p>Could someone tell me what's going wrong here?</p>

<p>I want to use this token information to pass it to the CreateProcessAsUser function from a windows service.</p>

<p>Thanks,
Ram</p>
