【发布时间】:2012-05-09 20:11:41
【问题描述】:
我是 C# 编码的新手,请帮助我,提前谢谢你..!!!
我正在尝试关注:
我正在开发小型 C# 应用程序以在远程服务器上执行批处理文件,以下是我的代码,我的大多数服务器都是 windows 2008 64bit,如果我 RDP 进入服务器,我可以执行批处理文件而不会出现任何错误,但是当我尝试通过下面的代码来做,它不起作用,没有抛出异常,但没有结果。
我的批处理文件包含以下命令:
@ECHO off
echo Running Remote Commands
date/t
time /t
COPY "\\xt0022\I$\abc\RemoteProcess\testcopy.bat" D:\ab\
date/t
time /t
-
try
{
string remotemachine = "Server1";
object[] theProcessToRun = { "D:\\ab\\test2.bat" };
ConnectionOptions theConnection = new ConnectionOptions();
theConnection.Impersonation = ImpersonationLevel.Impersonate;
theConnection.EnablePrivileges = true;
ManagementScope theScope = new ManagementScope("\\\\" + remoteMachine + "\\root\\cimv2", theConnection);
ManagementClass theClass = new ManagementClass(theScope, new ManagementPath("Win32_Process"), new ObjectGetOptions());
theClass.InvokeMethod("Create", theProcessToRun);
}
catch (Exception ex)
{
}
如果我调试代码,它会显示“推导 = 函数评估超时。”
我必须用 RUNAS .. 运行它吗?如果是.. 谁能帮我解决这些代码或方法..?
谢谢大家..!
【问题讨论】: