启动PsExec之后,C#在远程计算机上运行批处理文件
|
基本上,我正在尝试运行在远程计算机上复制的批处理文件,顺便说一下,这是我第一次尝试进行编码,因此请保持友好,但如果需要请批评一下,我仍在学习语言,并且不得不花3个小时才能达到目标,感谢上帝,Google,哈哈。
码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void cleanerBtn_Click(object sender, EventArgs e)
{
//Copying Batch File to Remote Host
string fileToCopy = \"C:\\\\Clean.bat\";
string newLocation = hostName.Text;
string newFile = (newLocation + \"\\\\clean.bat\");
System.IO.File.Copy(fileToCopy, newLocation);
//Run PsExec
string psExec = \"psexec -s \"+newLocation+\" cmd\";
System.Diagnostics.Process.Start(\"CMD.exe\", psExec);
//Run Batch File using PsExec
//Removing Batch File from Remote Host
System.IO.File.Delete(newFile);
}
}
}
提前致谢。
没有找到相关结果
已邀请:
2 个回复
梆晨灸碾
览幕堤分
相信您会得到预期的结果。如果不是,则可能要确保“ 3”在PATH环境变量的目录中。 另外,您可能有兴趣研究ProcessStartInfo以指定可以为执行流程设置的其他不同参数。