Process p = new Process();
                p.StartInfo.FileName = @"E:\Development\Fugoo Device\Develop\Fugoo V1.1\Fugoo.Device\Output\Data\MoreStore\DownloadFolder\Youtube_1.0.0.msi";
                System.Threading.Thread.Sleep(3000);
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError = true;
                p.StartInfo.CreateNoWindow = true;
                p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                p.Start();
                p.StandardOutput.ReadToEnd();
                p.WaitForExit(); 
                p.Close(); 程序执行到p.Start()后就出现异常,如果把执行的是一个exe文件就不会报错,为什么呢?请各位帮帮忙,谢谢

解决方案 »

  1.   

    不能直接调用,要间接调用http://topic.csdn.net/u/20071012/01/fe3f6356-c231-4bdd-9d5e-065711e0164d.html?849544465
      

  2.   

    直接调用默认执行程序是explorer.exe
    你要用给msiexec.exe传参执行msi文件
      

  3.   


    不知道是Process的问题还是MSI需要参数,先试试下面这个        [DllImport("shell32.dll", EntryPoint = "ShellExecute")]
            public static extern int ShellExecute(
                int hwnd,
                string lpOperation,
                string lpFile,
                string lpParameters,
                string lpDirectory,
                int nShowCmd
            );
      

  4.   

            private void StartInstall(string fileName)
            {
                try
                {
                    Process p = new Process();
                    string file = fileName;
                    p.StartInfo.FileName = "msiexec.exe";
                    p.StartInfo.Arguments = string.Format(" /i {0} /passive ", file);
                    System.Threading.Thread.Sleep(3000);
                    p.StartInfo.UseShellExecute = false;
                    p.StartInfo.RedirectStandardInput = true;
                    p.StartInfo.RedirectStandardOutput = true;
                    p.StartInfo.RedirectStandardError = true;
                    p.StartInfo.CreateNoWindow = true;
                    p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    p.Start();
                    p.StandardOutput.ReadToEnd();
                    p.WaitForExit();
                    p.Close();             }
                catch(Exception ex)
                {
                    Fugoo.Themes.Controls.Dialogs.MessageBox.Show(ex.ToString());
                }
            }fileName 实际就是E:\Development\Fugoo Device\Develop\Fugoo V1.1\Fugoo.Device\Output\Data\MoreStore\DownloadFolder\Youtube_1.0.0.msi但是这样根本就没有执行E:\Development\Fugoo Device\Develop\Fugoo V1.1\Fugoo.Device\Output\Data\MoreStore\DownloadFolder\Youtube_1.0.0.msi这个文件,请问各位高手,谢谢了
      

  5.   


    具体怎么传呢?
    private void StartInstall(string fileName)
      {
      try
      {
      Process p = new Process();
      string file = fileName;
      p.StartInfo.FileName = "msiexec.exe";
      p.StartInfo.Arguments = file;
      System.Threading.Thread.Sleep(3000);
      p.StartInfo.UseShellExecute = false;
      p.StartInfo.RedirectStandardInput = true;
      p.StartInfo.RedirectStandardOutput = true;
      p.StartInfo.RedirectStandardError = true;
      p.StartInfo.CreateNoWindow = true;
      p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
      p.Start();
      p.StandardOutput.ReadToEnd();
      p.WaitForExit();
      p.Close();    }
      catch(Exception ex)
      {
      Fugoo.Themes.Controls.Dialogs.MessageBox.Show(ex.ToString());
      }
      }
    参数fileName实际就是E:\Development\Fugoo Device\Develop\Fugoo V1.1\Fugoo.Device\Output\Data\MoreStore\DownloadFolder\Youtube_1.0.0.msi文件,
    我这样不会执行E:\Development\Fugoo Device\Develop\Fugoo V1.1\Fugoo.Device\Output\Data\MoreStore\DownloadFolder\Youtube_1.0.0.msi
    请问该如何做?谢谢