I already tried to solve my problem the LogonUser of the API using this link http://www.yqcomputer.com/
It runs well giving my username and pwd of my local computer. I tried the same thing with the account of a colleague. In both cases I runs!
But when I tried it of our test server with an admin account, it doesn't work.
I become an error 1326 !?!? I connect myself in remote using the domain, username and pwd parameters I gave the Logon method without problem.
It should be something with rights, shouldn't it ?
I appreciate any suggestion to solve this problem.
private void DoWorkImpersonating(string p_username,string p_pwd, string p_domain)
int ret=0 ;
bool loggedOn = LogonUser(
// Logon type = LOGON32_LOGON_NETWORK_CLEARTEXT.
// Logon provider = LOGON32_PROVIDER_DEFAULT.
// The user token for the specified user is returned here.
// Call GetLastError to try to determine why logon failed if it did not succeed.
if (loggedOn == false)
ret = GetLastError();
this.ResultTb.Text = "LogonUser() failed with error code: " + ret + "\r\n";
if (ret != 0)
throw new Exception ("Invalid Username or Password");
IntPtr token2 = new IntPtr(l_token1);
WindowsIdentity l_Wid = new WindowsIdentity (token2);
WindowsImpersonationContext l_mWIC = l_Wid.Impersonate();
//do work here impersonating the caller Identity