1
我要运行用C#CMD命令在Windows中安装的服务,我使用的代码如下:cmd命令不执行在C#
class Program
{
static void Main(string[] args)
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.CreateNoWindow = false;
startInfo.FileName = "cmd.exe";
startInfo.Arguments =
"\"C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\installutil.exe\" \"D:\\Projects\\MyNewService\\bin\\Release\\MyNewService.exe\"";
process.StartInfo = startInfo;
process.Start();
}
}
但这个方案不工作。如果我在cmd.exe中运行这个命令可以正常工作,但是当我运行这个项目时不要执行命令并且MyNewService.exe不要安装。
我的问题在哪里? 你帮我吗?
您是否运行cmd runas管理员? –
是的,我的项目以管理员身份运行。在此之前,我添加了startInfo.Verb =“runas”;但不工作。 –