请教的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文件就不会报错,为什么呢?请各位帮帮忙,谢谢
...全文
122 6 打赏 收藏 转发到动态 举报
写回复
用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
  • 打赏
  • 举报
回复
课程基础概述本门课程,大喵将会打着大家从零打造一款属于大家自己的 CLI命令行脚手架工具,本课程主要面向新手同学,对命令行工具开发,前端工具开发感兴趣的同学,可以通过本门课程学习到如何使用Node.JS开发一款适配自身项目特色的脚手架命令行工具。并且也会带着大家推送自己开发完成的CLI工具到NPM线上仓库,供所有人下载安装使用。整个课程,大喵会详细讲解所需要依赖的第三方模块包的具体使用,让同学们可以举一反三开发具备自身特色的CLI工具,最终大喵会运用到前面所讲解的基础内容,独立自主开发一个具备 damiao [ add | delete | list | init ] 四种子命令的CLI脚手架工具。CLI命令行工具命令行工具(Cmmand Line Interface)简称cli,顾名思义就是在命令行终端中使用的工具。我们常用的 git 、npm、vim 等都是 cli 工具,比如我们可以通过 git clone 等命令简单把远程代码复制到本地。在目前前端工程大流行的环境下,vue-cli、create-reate-app、angular-cli 等等方便快捷的命令行脚手架工具诞生,极大的提升了我们的开发效率与质量,我们可以通过这些脚手架工具在本地快速构建我们的开发项目。 课程目录结构1、CLI课程介绍   2、CLI课程纲领和讲师介绍3、CLI课程内容概述    4、CLI命令行工具及场景应用5、CLI课程准备工具和技术   6、CLI课程收获和收益  7、CLI课程实战案例介绍   8、npm CLI 命令行工具发展现状9、创建第一个命令行自定义命令   10、process.argv 接收命令行参数11、commander 工具使用介绍一   12、commander 工具使用介绍二13、inquirer 工具使用介绍   14、ora 加载工具使用介绍15、chalk 颜色工具使用介绍   16、download-git-repo 仓库工具介绍17、创建脚手架命令   18、创建命令可执行文件19、damiao add 命令行指令开发   20、damiao add 模板录入校验21、damiao delete 命令行指令开发   22、damiao list 命令行指令开发23、damiao init 初始化项目指令开发   24、damiao init 指令参数输入校验25、damiao 命令行指令测试.mp4  26、创建npm个人账号及发布npm仓库27、全局安装脚手架工具

110,550

社区成员

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

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

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