Search code examples
c#wmi

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?

EDIT: It works with an admin, looks like it's the user..

I've followed this guide here to try and give permissions without sucess. https://support.infosim.net/demo/wmi/wmi.html

Help please


Solution

  • Basically, you can't do it with an account that has limited permissions. You can tweak the permissions on the WMI object to read but not to write it does not work at all.