LogonUser() failed with error code 1326
Bonjour à tous,
Voilà je développe une appli qui se log à distance sur des serveurs par le biais de LogonUser().
Sous Windows aucun problème pour faire la connexion UNC :
\\serveur\partage\dossier\fichier.
Quand je lance mon thread : j'ai une erreur 1326 :
Citation:
LogonUser() failed with error code 1326
Voici ma fonction :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
public void pathAccess()
{
IntPtr token;
WindowsIdentity wi;
//string domainNameNet = domainName + ".net";
if (LogonUser("jsmith","domain.net","xxxxx",
8, // LOGON32_LOGON_NETWORK_CLEARTEXT
0, // LOGON32_PROVIDER_DEFAULT
out token))
{
wi = new WindowsIdentity(token);
WindowsImpersonationContext wic = wi.Impersonate();
File.Copy(@"\\dallas\c$\toto.txt", @"C:\result.txt");
wic.Undo();
CloseHandle(token);
}
else
{
MessageBox.Show("LogonUser() failed with error code " + Marshal.GetLastWin32Error());
}
} |
Quelqu'un pourrait éclairer ma lanterne ? Merci d'avance.
EDIT : les DllImport de ma classe :
Code:
1 2 3 4 5
|
[DllImport("advapi32.dll", SetLastError = true)]
private static extern bool LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, out IntPtr phToken);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
private extern static bool CloseHandle (IntPtr handle); |