After seeing your post I decided to figure LogonUser out. Here's what I
found:
First of all, the Declare in the API viewer is wrong in that LogonUser is a
function exported by ADVAPI32.DLL, not KERNEL32.DLL. Next, when I was
finally able to call the function, initially it returned False. After
checking the Win32 SDK documentation and knowledge base, I found out that
the calling process has to have certain privileges. In other words, the
user or service that is calling the function must have the following
advanced user rights set up in the User Manager:
Privilege Display Name (in User Manager, User Rights Policy)
----------------------------------------------------------------------------
-------------------------------------
SeTcbPrivilege Act as part of the operating system
SeAssignPrimary Replace a process level token
SeIncreaseQuota Increase quotas
Having said all of that, here's an example on how to use LogonUser:
Dim bReturn As Boolean
Dim hToken As Long
Dim sUserName As String
Dim sPassword As String
Dim sDomain As String
sUserName = "some user name"
sPassword = "somepassword"
sDomain = "SOMEDOMAIN"
bReturn = LogonUser(sUserName, sDomain, sPassword,
LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, hToken)
CloseHandle (hToken)
The phToken argument is a handle to the user that is logged on by
LogonUser. You can use this token handle in calls to the
ImpersonateLoggedOnUser and CreateProcessAsUser functions.
Let me know how this works for you.
--
Keith Benedict
Software Engineer
Triad Systems Corporation
Quote:
> I am wondering if anyone could please send me an example of using the
> LogonUser API call written in VB.
> We are writting an application that needs to logon to the network and
would
> like to use this call. I think our problem stems around the phToken that
> must be passed. Which we have no idea about.
> Any help or examples would be greatly appreciated.
> Thanks,
> Jeff Levy