静默安装vcredist_x86.exe 目录带空格

版权声明:随意乱写,切勿当真! https://blog.csdn.net/pehao/article/details/79570616
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();
}

猜你喜欢

转载自blog.csdn.net/pehao/article/details/79570616
今日推荐