Пример #1
0
 static void ImpersonateByService()
 {
     //using (WindowsImpersonationContext wic = ImpersonateService.GetImpersonationContext("bpm_admin", "Abc123", "tutorabc"))
     using (WindowsImpersonationContext wic = ImpersonateService.GetImpersonationContext("longoriayou", "Fgl77vxs589", "tutorabc"))
     {
         Console.WriteLine("impersonating...: " + WindowsIdentity.GetCurrent().Name);
         foreach (string dir in Directory.GetDirectories(directoryPath))
         {
             Console.WriteLine(dir);
         }
         wic.Undo();
     }
 }
Пример #2
0
 public static WindowsImpersonationContext GetImpersonationContext(string userName, string password, string domainName)
 {
     return(new WindowsIdentity(ImpersonateService.GetDupToken(userName, password, domainName)).Impersonate());
 }