Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

WTSQueryUserToken

Posted on 2006-07-06
2
Medium Priority
?
1,244 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

730 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