So for the past days I have been stuck with LogonUserA which always threw an error 1008 - ERROR_NO_TOKEN "An attempt was made to reference a token that does not exist.". It did not matter what logon type or logon provider I passed to the function - it could be interactive/network logon for domain profiles or even interactive logon for a local account. It just always failed.
After I had almost pulled my hair out, I checked out the LogonUserW function. They both have identical signatures and their documentation is absolutely the same to the letter.
LogonUserA https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-logonusera
LogonUserW https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-logonuserw
These were my signatures
[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool LogonUserA(
string lpszUsername,
string lpszDomain,
string lpszPassword,
int dwLogonType,
int dwLogonProvider,
out IntPtr phToken
);
[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool LogonUserW(
string lpszUsername,
string lpszDomain,
string lpszPassword,
int dwLogonType,
int dwLogonProvider,
out IntPtr phToken
);
I have also tried using phToken as a ref for LogonUserA, but it did not change anything.
Now, my question is, is there someone who knows the difference? Or perhaps the reason for the 1008 while using LogonUserA?
Thanks!