本文介绍了如何以管理员身份运行文件cmd?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有:
I have:
void RunCmdFile(string command)
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
//startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Verb = "runas";
startInfo.Arguments = "/k cd c:\\TestCasPol\\";
startInfo.Arguments = command;
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
}
command = "caspol.cmd"
命令没有运行。
帮帮我?
Command not run.
Help me?
推荐答案
startInfo.Arguments = "/k cd c:\\TestCasPol\\";
startInfo.Arguments = command;
在这些行之后,命令的参数仅为 caspol.cmd
!!!
您要做的是更改当前目录而不是运行外部命令文件...
您应该使用&组合命令命令行的运算符...
After these lines the arguments for command is caspol.cmd
only!!!
What you want to do is to change the current directory and than run the external command file...
You should combine the command using & operator of command line...
startInfo.Arguments = "/k cd c:\\TestCasPol\\ & " + command;
这篇关于如何以管理员身份运行文件cmd?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!