请教的Process.Start()问题

pengfangxu8 2010-05-10 01:44:44
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文件就不会报错,为什么呢?请各位帮帮忙,谢谢
...全文
127 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
pengfangxu8 2010-05-10
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 mngzilin 的回复:]
直接调用默认执行程序是explorer.exe
你要用给msiexec.exe传参执行msi文件
[/Quote]

具体怎么传呢?
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
请问该如何做?谢谢
pengfangxu8 2010-05-10
  • 打赏
  • 举报
回复
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这个文件,请问各位高手,谢谢了
ZengHD 2010-05-10
  • 打赏
  • 举报
回复

不知道是Process的问题还是MSI需要参数,先试试下面这个

[DllImport("shell32.dll", EntryPoint = "ShellExecute")]
public static extern int ShellExecute(
int hwnd,
string lpOperation,
string lpFile,
string lpParameters,
string lpDirectory,
int nShowCmd
);

mngzilin 2010-05-10
  • 打赏
  • 举报
回复
直接调用默认执行程序是explorer.exe
你要用给msiexec.exe传参执行msi文件
mayonglong 2010-05-10
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 mngzilin 的回复:]
不能直接调用,要间接调用

http://topic.csdn.net/u/20071012/01/fe3f6356-c231-4bdd-9d5e-065711e0164d.html?849544465
[/Quote]

up~~
mngzilin 2010-05-10
  • 打赏
  • 举报
回复

111,094

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧