问题
..
当我打开开始>运行> CMD
并写下这个命令..
c:> msg \ server:“192.168.6.5”*“发送你好”
obove命令正确执行
但是
当我从c#.net运行cmd时,此命令会出现此错误
private void button3_Click(object sender, EventArgs e)
{
Process.Start("cmd.exe");
}
然后编写相同的命令
c:> msg \ server:“192.168.6.5”*“发送你好”
输出消息: msg不被识别为内部或外部命令......
有什么问题? 请帮忙
答案 0 :(得分:0)
1)如果您使用64位,则可能必须使用“C:\ windows \ sysnative \ msg.exe”。或者使用System.Environment.GetEnvironmentVariable获取路径,然后将其传递给新的ProcessStartInfo对象。 e.g。
string path = System.Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.Machine);
// add in the extra path parts if required
ProcessStartInfo pinfo = new ProcessStartInfo();
pinfo.WorkingDirectory = "whatever";
pinfo.FileName = "CMD.exe";
pinfo.Arguments = "whatever";
pinfo.EnvironmentVariables["Path"] = path;
然后将其传递给Process.Start
2)另外,从文档“用户必须具有发送消息的发送消息访问权限。”,这将取决于您正在运行该进程的权限。