Results 1 to 4 of 4

Thread: Logon function

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2005
    Posts
    29

    Logon function

    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

  2. #2
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: Logon function

    System.Environment.UserName
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2005
    Posts
    29

    Re: Logon function

    Quote Originally Posted by bmahler
    System.Environment.UserName
    That's not the token associated with the user, it's just the username. And the code must get the token of any user, not only the current user.

    The code must also verify the password the user has entered.

    Is this possible without that WinAPI call?

  4. #4
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: Logon function

    My appologies, I didn't fully read your question, but after some searching, I believe that you will need to use the api's.
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width