Solved

WTSQueryUserToken

Posted on 2006-07-06
2
1,167 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

895 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now