Solved

WTSQueryUserToken

Posted on 2006-07-06
2
1,181 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …

735 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