Bonjour,

Je souhaite exécuter une commande sur un poste distant mais en utilisant un compte local du poste distant.

voici le code que j'utilise :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 
if (LogonUser(_strUsername, _strDomain, _strPassword, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, out hToken))
{
         System.Diagnostics.Trace.TraceInformation("  Logon succeed!");
 
         if (DuplicateToken(hToken, 2, out hTokenDuplicate))
         {
                oWindowsIdentity = new WindowsIdentity(hToken);
                oWindowsImpersonationContext = oWindowsIdentity.Impersonate();
 
                // Mon traitement
 
                oWindowsImpersonationContext.Undo();
 
                oWindowsImpersonationContext.Dispose();
                oWindowsImpersonationContext = null;
                oWindowsIdentity.Dispose();
                oWindowsIdentity = null;
          }
          if (hTokenDuplicate != IntPtr.Zero) CloseHandle(hTokenDuplicate);
}
else 
{
         System.Diagnostics.Trace.TraceWarning("  Logon failed  : " + GetLastError());
}
Ce code fonctionne très bien avec un compte d'un domaine NT mais pas avec un compte local de la machine distante.
Quelqu'un aurait une idée ?

D'avance merci.