Home
Forums
New posts
Search forums
Articles
Latest reviews
Search resources
Members
Current visitors
Newsgroups
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Home
Forums
Newsgroups
Microsoft DotNet
Microsoft VB .NET
problems with Impersonate
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Guest, post: 4270052"] Hi! I've found a piece of code which should help me to impersonate within a program. When I put in the piece in my Studio.net and I compile it, it fails to authenticate. The MsgBox("Authentication Faild!") is shown then. I'm a VB.NET beginner and I've no idea how to solve the problem. Thanks in advanced Juan Module Module 1 Declare Auto Function LogonUser Lib "advapi32.dll" (ByVal lpszUsername As String, ByVal lpszDomain As String, ByVal lpszPassword As String, ByVal dwLogonType As Integer, ByVal dwLogonProvider As Integer, ByRef phToken As IntPtr) As Integer Declare Auto Function ImpersonateLoggedOnUser Lib "advapi32.dll" (ByVal hToken As IntPtr) As Integer Declare Auto Function RevertToSelf Lib "advapi32.dll" () As Integer Sub Main() If impersonateValidUser("Peter", "MyDomain", "PetersPassword") then System.Diagnostics.Process.Start("C:\windows\notepad.exe") undoImpersonation() else MsgBox("Authentication Failed!") end if End Sub Function impersonateValidUser(username as String, Domain as String, password as String) as boolean Dim LogonType as Integer Dim LogonProvider as Integer Dim Tk as IntPtr LogonType = 2 'Interactive LogonProvider = 0 'Default Provider If LogonUser(username ,Domain ,password , LogonType, LogonProvider ,Tk) <> 0 then if ImpersonateLoggedonUser(Tk) <> 0 then impersonateValidUser ="True" else impersonateValidUser ="False" End if End If End function Sub undoImpersonation() RevertToSelf() End Sub End Module [/QUOTE]
Verification
Post reply
Home
Forums
Newsgroups
Microsoft DotNet
Microsoft VB .NET
problems with Impersonate
Top