我正在尝试从C#程序中卸载一些可再发行组件,因此我查看存储在app.config中的程序ID值,然后尝试运行msiexec以卸载它们。如果我将参数存储在ProcessStartInfo对象中,则调用不起作用,但如果我调用Process.Start("stuff")
它就可以正常工作。这是为什么?我想使用ProcessStartInfo,以便我可以更好地控制弹出的窗口。
这不起作用:
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
int numberOfKeys = ConfigurationManager.AppSettings.Count;
for (int i = 0; i < numberOfKeys; i++)
{
string[] guid = ConfigurationManager.AppSettings.GetValues(i);
startInfo.Arguments = "/X " + guid[0] + " /l*vx log" + i.ToString() + ".txt";
startInfo.CreateNoWindow = true;
startInfo.FileName = "msiexec.exe";
process.StartInfo = startInfo;
var result = process.Start();
}
但这样做:
int numberOfKeys = ConfigurationManager.AppSettings.Count;
for (int i = 0; i < numberOfKeys; i++)
{
string[] guid = ConfigurationManager.AppSettings.GetValues(i);
var result = Process.Start("msiexec.exe", "/X " + guid[0] + " /l*vx log" + i.ToString() + ".txt");
}
任何人都可以解释原因吗?
答案 0 :(得分:0)
我通过在通话后放入睡眠(10000)来使其工作。谢谢你的建议!