Solved

WTSQueryUserToken

Posted on 2006-07-06
2
1,178 Views
Last Modified: 2008-03-10
Hello,

   I am trying to use the WTSQueryUserToken function.  Does this declaration look correct?


'BOOL WTSQueryUserToken(
'     ULONG SessionId,
'     PHANDLE phToken
');

Declare Auto Function WTSQueryUserToken Lib "Wtsapi32.dll" (ByVal SessionId As Integer, ByRef phToken As IntPtr) As Boolean

 Declare Unicode Function GetLastError Lib "kernel32" () As Int32

Sub Test()

Try
            Dim hToken As IntPtr

            If WTSQueryUserToken(1, hToken) Then
                LogErrorData(GetLastError)
            Else
                LogErrorData("WTSQueryUserToken: " & GetLastError)
            End If

Catch ex as Exception
     Err.Raise ex.message
End Try
End Sub
0
Comment
Question by:pyrokin
2 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 17055254
ULONG = UInt32 = UnmanagedType.U4

System.Runtime.InteropServices.MarshalAs attribute:

   Private Declare Auto Function WTSQueryUserToken Lib "Wtsapi32.dll" (<MarshalAs(UnmanagedType.U4)> ByVal SessionId As Integer, ByRef phToken As IntPtr) As Boolean

Bob
0
 
LVL 1

Author Comment

by:pyrokin
ID: 17055298
Thanks so much.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question