我遇到了Windows更新静默安装的小问题。
为什么我需要它?我有一些系统磁盘的副本,我用它来重新安装win7(有.net框架,visual studio,java和50多个其他应用程序安装在一起的优势)。
然后我需要安装一些重要的更新。我用c#编写了小的用法,工作正常除外
即使使用 startInfo.Arguments = "/quiet/norestart/passive";
,安装也不会保持沉默。
不沉默:我的意思是至少有两个窗口,比如询问我是否需要安装或重启选项。
问题出现在另一个论坛How are people deploying HOTFIXES .msu files?
但对我来说,解决方案有点不明确。有人知道如何解决它吗?
同样,startInfo.Arguments = "/quiet/norestart/passive";
或startInfo.Arguments = @"/qb!"+ "REBOOT=ReallySuppress"+ @"/qn";
无效,并在链接中解释原因。
textBox1.Text
是所有修补程序和更新在一个目录中的位置。
{
string[] filePaths = Directory.GetFiles(textBox1.Text);
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = true;
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
//startInfo.Arguments = "/quiet/norestart/passive";
for (int i = 0; i < filePaths.Length; i++)
{
label1.Text = "Working";
startInfo.FileName = filePaths[i];
startInfo.Arguments = @"/qb!"+ "REBOOT=ReallySuppress"+ @"/qn";
try
{
Process.Start(startInfo.FileName).WaitForExit();
}
catch (Exception exc)
{
MessageBox.Show(exc.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
label1.Text = " Done ";
}
答案 0 :(得分:1)
首先,你只是将没有空格的参数链接在一起,因此只传递一个可能不起作用的参数。尝试
startInfo.Arguments = "/qb! REBOOT=ReallySuppress /qn"
答案 1 :(得分:0)
最后我使用纯CMD线绕过它。没有窗口的静默安装,除了例外。
private void button1_Click(object sender, EventArgs e)
{
string[] filePaths = Directory.GetFiles(textBox1.Text);
Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.EnableRaisingEvents = false;
for (int i = 0; i < filePaths.Length; i++)
{
if (i == 0) { label1.Text = "Working On first task"; }
process.StartInfo.Arguments = "/C " + "@" + "\"" + filePaths[i] + "\"" + " /quiet /norestart";
process.Start();
process.WaitForExit();
label1.Text = (100 * i / filePaths.Length).ToString() + " % is done";
}
label1.Text = "Done";
}