LogonUser function declaration problem 
Author Message
 LogonUser function declaration problem

I'm trying to use the LogonUser function so that an ActiveX dll can run as a
specific user on my IIS machine.  The API Viewer gives me the declaration
of:

Public Declare Function LogonUser Lib "kernel32" Alias "LogonUserA" (ByVal
lpszUsername As String, ByVal lpszDomain As String, ByVal lpszPassword As
String, ByVal dwLogonType As Long, ByVal dwLogonProvider As Long, phToken As
Long) As Long

But when I look in kermel32 (using QuickView from the Windows Explorer), I
don't see LogonUserA listed as one of the functions.

Any idea where this function is?  Also, has anyone used the function for any
reason - I'd like to hear how it worked out.

Matt




Thu, 03 May 2001 03:00:00 GMT  
 LogonUser function declaration problem
Thank you to Guillermo for helping me find the function - Now on th problem
#2!

According to the documentation for LogonUser in MSDN, the function returns a
zero if it fails, and something non-zero if it is successfull.  Mine (of
course) is returning zero.

Sooooo,  I'm now calling GetLastError right after my LogonUser function and
guess what - it also returns zero.  According to MSDN - a zero from
GetLastError means everthing was OK.

Here is the code from my class:

Private Declare Function LogonUser Lib "advapi32.dll" Alias "LogonUserA" _
  (ByVal lpszUsername As String, ByVal lpszDomain As String, _
   ByVal lpszPassword As String, ByVal dwLogonType As Long, _
   ByVal dwLogonProvider As Long, phToken As Long) As Long

Private Declare Function GetLastError Lib "kernel32" () As Long

Private Const LOGON32_LOGON_BATCH = 4
Private Const LOGON32_PROVIDER_DEFAULT = 0

Public Function LogonNewUser(User As String, Domain As String, Password As
String) As Long

    Dim Token As Long
    Dim RetVal As Long
    Dim LastError As Long

    RetVal = LogonUser(User, Domain, Password, _
                                         LOGON32_LOGON_BATCH,
LOGON32_PROVIDER_DEFAULT, _
                                        Token)
    LastError = GetLastError()
    If RetVal = 0 Then
           MsgBox "LogonUser API call failed.  Last error was " &
CStr(LastError)
           LogonNewUser = 0
    Else
           LogonNewUser = Token
    End If

End Function

Any help would be appriciated
Matt



Thu, 03 May 2001 03:00:00 GMT  
 LogonUser function declaration problem

Quote:

>According to the documentation for LogonUser in MSDN, the function returns
a
>zero if it fails, and something non-zero if it is successfull.  Mine (of
>course) is returning zero.

>Sooooo,  I'm now calling GetLastError right after my LogonUser function and
>guess what - it also returns zero.  According to MSDN - a zero from
>GetLastError means everthing was OK.

First the bad news...
The GetLastError API call returns the error code set by the last call made,
which sounds good, but in between your call to LogonUser and your call to
GetLast Error the VB runtime has made at least one, and probably many, DLL
calls itself.  Your error code has been long lost by being overwritten.

Now for the good news...
When your code makes a DLL call the first thing VB does on return is call
GetLastError so that the info can be retrieved.  It stuffs it into the Err
object for you.  What you need to do is:

If LogonUser(....)=0 then
  msgbox "Failed with error " & CStr(Err.LastDLLError)
End If



Thu, 03 May 2001 03:00:00 GMT  
 LogonUser function declaration problem
Hi,

This function is in the advapi32 library:

Private Declare Function LogonUser Lib "advapi32.dll" Alias " LogonUserA"
(ByVal lpszUsername As String, ByVal lpszDomain As String, ByVal
lpszPassword As String, ByVal dwLogonType As Long, ByVal dwLogonProvider As
Long, phToken As Long) As Long

Nos vemos.
Guillermo
---
Te invito a mis pginas sobre Visual Basic en espa?ol
http://guille.costasol.net/
=====================================================

Quote:

>I'm trying to use the LogonUser function so that an ActiveX dll can run as
a
>specific user on my IIS machine.  The API Viewer gives me the declaration
>of:

>Public Declare Function LogonUser Lib "kernel32" Alias "LogonUserA" (ByVal
>lpszUsername As String, ByVal lpszDomain As String, ByVal lpszPassword As
>String, ByVal dwLogonType As Long, ByVal dwLogonProvider As Long, phToken
As
>Long) As Long

>But when I look in kermel32 (using QuickView from the Windows Explorer), I
>don't see LogonUserA listed as one of the functions.

>Any idea where this function is?  Also, has anyone used the function for
any
>reason - I'd like to hear how it worked out.

>Matt





Fri, 04 May 2001 03:00:00 GMT  
 LogonUser function declaration problem
Did you ever resolve this?  We ran into this same problem so I wrote a C
program that calls LogonUser().  It works fine on my machine but my
colleague is getting error code 1314 when he runs the same program on his
machine.  The description of this error code is "A required privilege is not
held by the client.".  We tried adding the "Log on as a service" and "Log on
as a batch job" to his user rights.  That didn't help.  For the 3rd and 4th
parameters to LogonUser() we are using LOGON32_LOGON_INTERACTIVE and
LOGON32_PROVIDER_DEFAULT.  Is there another user right that could be
missing?

Quote:

>Thank you to Guillermo for helping me find the function - Now on th problem
>#2!

>According to the documentation for LogonUser in MSDN, the function returns
a
>zero if it fails, and something non-zero if it is successfull.  Mine (of
>course) is returning zero.

>Sooooo,  I'm now calling GetLastError right after my LogonUser function and
>guess what - it also returns zero.  According to MSDN - a zero from
>GetLastError means everthing was OK.

[snip]
Quote:

>Any help would be appriciated
>Matt



Mon, 07 May 2001 03:00:00 GMT  
 LogonUser function declaration problem
Ok, one thing we've learned is that changing a users rights via User Manager
is not automatic.  You have to change the right and then log out and back in
for the change to take effect. :-(

--

Craig Weeks             <><
PSW Technologies, Inc.
6300 Bridgepoint Pkwy
Bldg. 3,  Suite 200
Austin, TX  78730
Voice:512-342-3517      FAX:512-343-9650

"Liberty exists in proportion to wholesome restraint."
 -- Daniel Webster, 1847



Mon, 07 May 2001 03:00:00 GMT  
 LogonUser function declaration problem
Can't say that I did ever resolve this.  Thanks to one of the replys to my
second post - I found out that both my VB and my VC++ implementation of
LogonUser are returning the 1314 - A required privledge is not held by the
client message.

I running this stuff from the Admin account of my NT box.  Hopefully someone
out there knows exactly which privledge is missing - and how to activate it.


Quote:
>Did you ever resolve this?  We ran into this same problem so I wrote a C
>program that calls LogonUser().  It works fine on my machine but my
>colleague is getting error code 1314 when he runs the same program on his
>machine.  The description of this error code is "A required privilege is
not
>held by the client.".  We tried adding the "Log on as a service" and "Log
on
>as a batch job" to his user rights.  That didn't help.  For the 3rd and 4th
>parameters to LogonUser() we are using LOGON32_LOGON_INTERACTIVE and
>LOGON32_PROVIDER_DEFAULT.  Is there another user right that could be
>missing?



Tue, 08 May 2001 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. tool to convert VC Dll functions declarations to VB declarations

2. LogonUser Function

3. LogonUser API function - question

4. LogonUser function - help please!

5. LogonUser Function

6. LogonUser advapi32.dll function

7. API functions declarations

8. 32 Bit ODBC API Function Declarations

9. Need ODBC API Function declaration

10. Visual Basic function declarations in C/Delphi?

11. Function declaration (translated from C)

12. VB6 Function Declaration for ZipDll.dll

 

 
Powered by phpBB® Forum Software