473,394 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

problems with Impersonate

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\notep ad.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

Nov 21 '05 #1
1 1683
Hi,

http://www.dotnet247.com/247referenc...28/144136.aspx

Ken
------------------

"Juan" <Ju**@discussions.microsoft.com> wrote in message
news:49**********************************@microsof t.com...
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\notep ad.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
Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Matthias Wohlmann | last post by:
Hi, I've got an ASP.NET Web-Application written in C#. In IIS 6.0 (Windows Server 2003) I have set the application to allow anonymous access, but instead of the default user I use an own...
0
by: Matthias Wohlmann | last post by:
Hi, I've got an ASP.NET Web-Application written in C#. In IIS 6.0 (Windows Server 2003) I have set the application to allow anonymous access, but instead of the default user I use an own...
0
by: Matthias Wohlmann | last post by:
Hi, I've got an ASP.NET Web-Application written in C#. In IIS 6.0 (Windows Server 2003) I have set the application to allow anonymous access, but instead of the default user I use an own...
0
by: e9425261 | last post by:
Hi, I've got an ASP.NET Web-Application written in C#. In IIS 6.0 (Windows Server 2003) I have set the application to allow anonymous access, but instead of the default user I use an own...
0
by: Matthias Wohlmann | last post by:
Hi, I already posted to this newsgroup, but didn't get an answer. So I try again: I've got an ASP.NET Web-Application written in C#. In IIS 6.0 (Windows Server 2003) I have set the application...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.