I'm trying to search for updates on a remote machine and all my attempts to do so with impersonation have failed stating that the username/password was not correct.
Here is a sample of my code. I've tried every LogonType available from SimpleImpersonation. 'System.UnauthorizedAccessException' is what is thrown whenever I try to call CreateInstance and my impersonated user never matches what it should.
I will state that I CAN impersonate local PC accounts and domain accounts but I cannot impersonate accounts that exist solely on other machines which is something I need.
Any help is appreciated!
Console.WriteLine(@"Original User: " + WindowsIdentity.GetCurrent().Name);
try
{
using (Impersonation.LogonUser("IP_ADDRESS", "USERNAME", "PASSWORD", LogonType.Interactive))
{
Console.WriteLine(@"Impersonating User: " + WindowsIdentity.GetCurrent().Name);
var type = Type.GetTypeFromProgID(@"Microsoft.Update.Session", target);
var session = (UpdateSession)Activator.CreateInstance(type);
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
Console.WriteLine(@"Current User: " + WindowsIdentity.GetCurrent().Name);
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire