Jump to content

LogonUser in advapi32.dll


Recommended Posts

Does anyone know how to use the LogonUser function in advapi32.dll?

This is what I have right now

Dim $RetCode
Dim $tokenHandle

$RetCode = DllCall("advapi32.dll", "bool", "LogonUser", "str", "UserName", "str", "Domain", "str", "Password", "dword", 2, "dword", 0, "ptr", $tokenHandle)

The problem is @error is always 1.

I have done some research on MSDN for the LogonUser function and that appears to be right, but if I open advapi32.dll in Dependency Walker there isn't a function called LogonUser within that DLL. But, for example, there is LogonUserEX, LogonUserW, LogonUserA. If I do a search for those on MSDN, it just returns "LogonUser". Not really sure what I am doing wrong for the call. Does anyone know?

BOOL LogonUser(

LPTSTR lpszUsername,

LPTSTR lpszDomain,

LPTSTR lpszPassword,

DWORD dwLogonType,

DWORD dwLogonProvider,

PHANDLE phToken

);

Edited by DarkMatter

[sub]Quantum mechanics: The dreams stuff is made of[/sub]

Link to comment
Share on other sites

In AutoIT bool type is int.

If I change

$RetCode = DllCall("advapi32.dll", "bool", "LogonUser", "str", "USERNAME", "str", "DOMAIN", "str", "PASSWORD", "dword", 2, "dword", 0, "ptr", $tokenHandle)

To

$RetCode = DllCall("advapi32.dll", "int", "LogonUser", "str", "USERNAME", "str", "DOMAIN", "str", "PASSWORD", "dword", 2, "dword", 0, "ptr", $tokenHandle)

AutoIT crashes...

[sub]Quantum mechanics: The dreams stuff is made of[/sub]

Link to comment
Share on other sites

Type of last param should be "ptr*"

I changed the last param to "ptr*"

Dim $RetCode
Dim $tokenHandle

$RetCode = DllCall("advapi32.dll", "bool", "LogonUser", "str", "USERNAME", "str", "DOMAIN", "str", "PASSWORD", "dword", 2, "dword", 0, "ptr*", $tokenHandle)
MsgBox(0,0,@error)

@error is still equal to one and $RetCode is set to nothing.

Edited by DarkMatter

[sub]Quantum mechanics: The dreams stuff is made of[/sub]

Link to comment
Share on other sites

I assumed it's pretty obvious that what rasim said still applies and you should have no trouble incorporating both fixes. Apparently not...

In any case, do yourself and everyone else a favor - read DllCall() reference in the helpfile very carefully.

"be smart, drink your wine"

Link to comment
Share on other sites

Got it thanks.

Dim $RetCode
Dim $tokenHandle

$RetCode = DllCall("advapi32.dll", "int", "LogonUser", "str", "USERNAME", "str", "DOMAIN", "str", "PASSWORD", "dword", 2, "dword", 0, "ptr*", $tokenHandle)
Edited by DarkMatter

[sub]Quantum mechanics: The dreams stuff is made of[/sub]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...