从远程计算机运行的Bat文件 [英] Bat file running from remote machine
问题描述
connOptions.Username=@"fdfdfdf";
connOptions.Password ="dfdfde" ;
connOptions.Impersonation = ImpersonationLevel.Impersonate;
connOptions.EnablePrivileges = true;
ManagementScope manScope = new ManagementScope(String.Format(@"\\{0}\ROOT\CIMV2", remoteMachine), connOptions);
manScope.Connect();
ObjectGetOptions objectGetOptions = new ObjectGetOptions();
ManagementPath managementPath = new ManagementPath("Win32_Process");
ManagementClass processClass = new ManagementClass(manScope, managementPath, objectGetOptions);
//Get the object on which the method will be invoked
// Get an input parameters object for this method
ManagementBaseObject inParams =
processClass.GetMethodParameters("Create");
inParams["CommandLine"] = sBatFile;
ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, null);
Console.WriteLine("Creation of the process returned: " + outParams["returnValue"]);
Console.WriteLine("Process ID: " + outParams["processId"]);
使用此代码,iam可以在远程计算机上创建进程,但看不到该记录.在我的bat文件中,有calc.exe
当iam在本地系统中执行时,calc appication出现在我的屏幕上.但是在远程环境中却可以创建进程,但是iam无法找到该appilication.我如何解决此问题.在这方面请提供帮助
在此先感谢
using this code iam able to create the process in remote machine but unable to see the appiction .In my bat file there is calc.exe
when iam executing in the local system calc appication appears on my screen .but in remote able to create the process but iam not able to find the appilication .how can i resolve this issue .kindly help in this regards
thanks in advance
推荐答案
ManagementPath myPath = new ManagementPath();
myPath.NamespacePath = @"root\CIMV2";
myPath.Server = MachineName; // Machine name is IP address of machine e.q. "192.168.0.222"
ConnectionOptions oConn = new ConnectionOptions();
oConn.Username = UserName;
oConn.Password = Password;
oConn.EnablePrivileges = true;
ManagementScope scope = new ManagementScope(myPath, oConn);
确保您的UserName/Password帐户在远程计算机上具有管理特权.
如果您要在域的一部分机器上执行用户名,则您的用户名还必须具有域名,例如"administrator@mycomplay.local"或"administrator @ mycompanydomain".
Make sure your UserName/Password account has administrative privileges on remote machine.
Also your UserName needs to have domain name along with it like "administrator@mycomplay.local" or "administrator@mycompanydomain" if you are trying to execute it on a machine which is part of domain.
这篇关于从远程计算机运行的Bat文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!