Thursday, 19 September 2013

Lauch a process on a remote machine with impersonation c#

Lauch a process on a remote machine with impersonation c#

I'm trying to launch a process using impersonation with WMI and C#.
Here's what I have so far:
var coptions = new ConnectionOptions();
coptions.Username = String.Format(@"{0}\{1}", machine.Domain,
machine.Username);
coptions.Password = machine.Password;
coptions.Impersonation = ImpersonationLevel.Impersonate;
coptions.EnablePrivileges = true;
var mScope = new ManagementScope(String.Format(@"\\{0}\root\cimv2",
machine.Address), coptions);
var mClass = new ManagementClass(mScope, new
ManagementPath("Win32_Process"), new ObjectGetOptions());
object[] generatorProcess = { @"C:\test\test1.exe" };
mClass.InvokeMethod("Create", generatorProcess);
Exception:
E_ACCESSDENIED at mClass.InvokeMethod
How can I do it?
PS: The user I'm launching the process with does not have admin
privileges, is it required?

No comments:

Post a Comment