Hello,

In this example , they use the winapi function LogonUser for logging on and obtaining the token of a windows user. But i don't like that in my vb.net program. Is it possible to obtain the token of a windows user in a more .Net way?

thx,

Tuur

This is how my code looks like:
VB Code:
  1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.  
  3.         Dim old As WindowsIdentity = WindowsIdentity.GetCurrent
  4.  
  5.         Dim token As System.IntPtr
  6.         Dim jos As WindowsIdentity
  7.  
  8.         If LogonUser("Tuur", System.Environment.MachineName, "blablabla", _
  9.             LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, token) Then
  10.  
  11.             jos = New WindowsIdentity(token)
  12.         End If
  13.  
  14.  
  15.     End Sub
  16.  
  17.     Private Declare Auto Function LogonUser Lib "advapi32.dll" ( _
  18.     ByVal lpszUsername As String, _
  19.     ByVal lpszDomain As String, _
  20.     ByVal lpszPassword As String, _
  21.     ByVal dwLogonType As Integer, _
  22.     ByVal dwLogonProvider As Integer, _
  23.     ByRef phToken As IntPtr) As Boolean
  24.  
  25.     Const LOGON32_LOGON_INTERACTIVE As Long = 2
  26.     Const LOGON32_PROVIDER_DEFAULT As Long = 0