简体   繁体   English

为什么在调用process.start时StartInfo.stuff不起作用,但是Process.start在C#中可以正常工作

[英]Why StartInfo.stuff doesn't work when calling process.start but Process.start works fine in C#

I'm trying to uninstall some redistributables from a C# program, so I look through the Program ID values stored in my app.config and then try to run msiexec to uninstall them. 我试图从C#程序中卸载一些可再发行文件,所以我浏览了存储在app.config中的程序ID值,然后尝试运行msiexec来卸载它们。 If I store the parameters in a ProcessStartInfo object the call doesn't work, but if I call Process.Start("stuff") it works fine. 如果我将参数存储在ProcessStartInfo对象中,则该调用将无法进行,但是如果我调用Process.Start("stuff")它将可以正常工作。 Why is that? 这是为什么? I want to use ProcessStartInfo so that I have more control over the window that pops up. 我想使用ProcessStartInfo以便对弹出的窗口有更多的控制。

This doesn't work: 这不起作用:

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();
}

But this does: 但这确实是:

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");
}

Can anyone explain why? 谁能解释为什么?

I got it to work by putting a Sleep(10000) after the call. 我通过在通话后放置Sleep(10000)使它工作。 Thanks for the suggestions! 感谢您的建议!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM