Re: logonuser api returns 127
From: Tom Shelton (tom_at_mtogden.com)
Date: 03/12/04
- Next message: Ken Tucker [MVP]: "Re: Testing For Highest Number in an array"
- Previous message: Ken Tucker [MVP]: "Re: PaintEventArgs what do i use for e in this code?"
- In reply to: Brent Burkart: "logonuser api returns 127"
- Next in thread: Lisa: "Re: logonuser api returns 127"
- Reply: Lisa: "Re: logonuser api returns 127"
- Reply: Brent Burkart: "Re: logonuser api returns 127"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 11 Mar 2004 22:05:00 -0800
On 2004-03-11, Brent Burkart <Brent.Burkart@wvmb.com> wrote:
> I have an impersonation procedure which was working before, but not any
> more. It is returning a 127. Any help is appreciated.
>
> Here is the code.
>
> 'First the call to the routine
> If Impersonate.impersonateValidUser("xxx", "xxx", "xxx") Then
>
> undoImpersonation()
>
> Else
>
> End If
>
> 'The routine
>
> 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
>
> Declare Auto Function GetLastError Lib "Kernel32.dll" () As Integer
>
> Function impersonateValidUser(ByVal username As String, ByVal Domain As
> String, ByVal 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
>
> Else
>
> Dim ret As Integer = GetLastError()
>
> MsgBox(ret)
>
> End If
>
> End Function
>
>
Brent,
First of all, are you absolutely sure that GetLastError is returning
127? Use of GetLastError is not good practice - and that applies to VB6
as well. The problem is that the runtime may make API calls, before you
call GetLastError - so the return value is useless. You should use
Marshal.GetLastWin32Error() instead...
Anyway, I haven't bothered to look up the error code... But, you can
get the system message associated with it by doing something like:
Dim errorCode As Integer = Marshal.GetLastWin32Error()
Dim ex As New Win32Exception(errorCode);
MessageBox.Show( _
String.Formate("Error: {0} - {1}", errorCode, ex.Message)
My guess is - especially looking down the thread - that you're running
into some kind of security related problem.
-- Tom Shelton [MVP] Powered By Gentoo Linux 1.4 I have often regretted my speech, never my silence. -- Publilius Syrus
- Next message: Ken Tucker [MVP]: "Re: Testing For Highest Number in an array"
- Previous message: Ken Tucker [MVP]: "Re: PaintEventArgs what do i use for e in this code?"
- In reply to: Brent Burkart: "logonuser api returns 127"
- Next in thread: Lisa: "Re: logonuser api returns 127"
- Reply: Lisa: "Re: logonuser api returns 127"
- Reply: Brent Burkart: "Re: logonuser api returns 127"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|