如何: 连接到一台远程计算机 - DanielWise
如何: 连接到一台远程计算机
2011-04-06 17:34
DanielWise
阅读(3319)
评论(1)
编辑
收藏
举报
ConnectionOptions connection = new ConnectionOptions(); //用户名不可以加域名, 要保证用户名和密码正确,否则报RPC is Unavaliable. connection.Username = "testUser"; connection.Password = "testPassword"; //允许权限提升 connection.EnablePrivileges = true; //委托方式身份模拟 connection.Impersonation = ImpersonationLevel.Delegate; //连接到WMI 的认证级别 connection.Authentication = AuthenticationLevel.Call; //不是ntdlmdomain,也不是kerberoes, 否则会提示Invalid Parameter. connection.Authority = "ntlmdomain:MYDOMAIN"; //地址使用IP或者机器全名 ManagementScope scope = new ManagementScope( "\\\\myIPAddress\\root\\CIMV2", connection); scope.Connect(); ManagementClass classInstance = new ManagementClass(scope, new ManagementPath("Win32_Process"), null); ManagementBaseObject inParams = classInstance.GetMethodParameters("Create"); //替换成你的可执行文件路径 inParams["CommandLine"] = "myExecuteFilePath"; ManagementBaseObject outParams = classInstance.InvokeMethod("Create", inParams, null);