Re: logonuser api returns 127

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Lisa (anonymous_at_discussions.microsoft.com)
Date: 03/12/04


Date: Fri, 12 Mar 2004 06:46:12 -0800

Brent,

I got that errors before. Try to use the full path. For example: C:\WINNT\system32\ADVAPI32.DLL instead of advapi32.dll.

However, I keeps getting 1314 errors on the Windows 2000 machine. I tried to grant "Act of part of OS", but did not work.

Can any one help on that?

Lisa
     
     ----- Tom Shelton wrote: -----
     
     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
     



Relevant Pages

  • VirtualAllocEx returns a bad pointer in some processes
    ... (ByVal hWnd As IntPtr, _ ... (ByVal hWndParent As IntPtr, _ ... ByVal lParam As String) As Integer ... Dim aihWnds As ArrayList ...
    (microsoft.public.vc.mfc)
  • Virtual memory C++ problem
    ... (ByVal hWnd As IntPtr, _ ... (ByVal hWndParent As IntPtr, _ ... ByVal lParam As String) As Integer ... Dim aihWnds As ArrayList ...
    (microsoft.public.win32.programmer.kernel)
  • SetPrinter for network printers
    ... Public dmDeviceName As String ... Public pSecurityDescriptor As IntPtr ... Dim pPrinterInfo As IntPtr ...
    (microsoft.public.dotnet.languages.vb)
  • Re: MapiSendMail and web browser
    ... Public Shared Function SendMail(ByVal strAttachmentFileName As String, ... Dim winhandle As IntPtr = New IntPtr ... Public Class MapiMessage ...
    (microsoft.public.win32.programmer.messaging)
  • Search pattern
    ... Dim strfile As String ... Dim bAddressFound As Boolean ... Dim strCurrentChar As String ...
    (comp.databases.ms-access)