string path = @"C:\Program Files"
string cmd = string.Format("start \"\" \"{0}vcredist_x86.exe\" /wait /q /norestart", path);//路径加"xxx"
Runcmd(cmd);
/// <summary>
/// 运行CMD
/// </summary>
/// <param name="cmd"></param>
public static void Runcmd(string cmd)
{
//start /wait vcredist_x86.exe /q /norestart
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/c C:\\Windows\\System32\\cmd.exe";
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.UseShellExecute = false;
startInfo.Verb = "RunAs";
startInfo.CreateNoWindow = true;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
Process process = new Process();
process.StartInfo = startInfo;
process.Start();
process.StandardInput.WriteLine(cmd);
process.StandardInput.WriteLine("exit");
process.StandardInput.AutoFlush = true;
process.WaitForExit();
process.Close();
}静默安装vcredist_x86.exe 目录带空格
最新推荐文章于 2025-10-04 15:41:10 发布
本文介绍了一种使用C#静默启动并管理CMD进程的方法,通过详细展示如何构造进程启动信息,实现指定路径下exe文件的静默运行及等待其完成。此方法适用于后台任务执行场景。
5025

被折叠的 条评论
为什么被折叠?



