简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM