使用Process运行Windows start.exe

安德烈斯

我正在通过Process以下命令安装MSI软件包

msiexec.exe /norestart /qn /l*v! mylog.log /i package.msi

使用此C#代码:

// Start the child process.
Process p = new Process();

// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "msiexec";
p.StartInfo.Arguments = "/norestart /qn /l*v! mylog.log /i package.msi";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WorkingDirectory = workingDir;

p.Start();

string output = p.StandardOutput.ReadToEnd();
bool status = p.WaitForExit(timeout);

现在,我想运行此命令,但要使用start.exe

start /wait msiexec.exe /norestart /qn /l*v! mylog.log /i package.msi

但是现在当我运行此命令时:

// Start the child process.
Process p = new Process();

// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "start";
p.StartInfo.Arguments = "/wait msiexec.exe /norestart /qn /l*v! mylog.log /i package.msi";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WorkingDirectory = workingDir;

p.Start();

string output = p.StandardOutput.ReadToEnd();
bool status = p.WaitForExit(timeout);

但是运行它时,我得到Exception系统找不到指定的文件也尝试设置UseShellExecute为,true但随后我得到另一个ExceptionProcess对象必须将UseShellExecute属性设置为false才能重定向IO流。

因此,可以start使用C#运行命令吗?

马约拉·维维卡南达(Mayura Vivekananda)

尝试这样的事情。

p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = @"/c start /wait msiexec.exe /norestart /qn /l*v! mylog.log /i package.msi";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WorkingDirectory = workingDir;

我认为您需要使用CMD来执行启动命令。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Process.Start()的exe无法正常工作

来自分类Dev

使用-Verb RunAs通过Start-Process运行cmd.exe,然后以管理员身份自动运行命令

来自分类Dev

Process.Start(“ Excel.exe”)立即退出

来自分类Dev

没有“ .exe”扩展名的Process.Start失败

来自分类Dev

在IIS中运行时,Process.Start cmd.exe不会运行作为参数传递的cmd文件

来自分类Dev

尝试使用Process.Start()以.txt文件作为参数打开.exe文件

来自分类Dev

Process.Start()不启动.exe文件(手动运行时有效)

来自分类Dev

如何使用 Python 杀死运行 exe 的 Windows

来自分类Dev

start.exe如何工作?

来自分类Dev

Process.Start()使.exe文件闪现打开,然后立即再次关闭

来自分类Dev

通过Process.start将大字符串内容作为参数传递给exe

来自分类Dev

如何在System.Diagnostics.Process.Start中将凭据/参数传递给exe

来自分类Dev

VB.net:从Process.Start(...)调用时exe文件无法正常工作

来自分类Dev

从 C# 中的 Process.Start 启动 cmd.exe 时,无法识别 Telnet 命令

来自分类Dev

使用qprocess运行.exe

来自分类Dev

Windows:如何获取启动工具来覆盖本地start.exe?

来自分类Dev

使用 Ant 通过 cmd.exe“start”命令启动 Java 程序

来自分类Dev

在.net中使用start.process运行R脚本

来自分类Dev

使用Docker在Windows容器中运行exe文件

来自分类Dev

我怎么知道编译是否成功或是否由于process.start()和devenv.exe而失败?

来自分类Dev

使用Process.Start()和Windows Task Scheduler的异常

来自分类Dev

Windows 10中缺少运行exe

来自分类Dev

无法在Windows XP上运行Python EXE

来自分类Dev

Cygwin 生成的 .exe 不直接从 Windows 运行

来自分类Dev

.exe不在C#中使用Process从其原始目录运行

来自分类Dev

以系统帐户运行exe

来自分类Dev

从bat文件运行exe

来自分类Dev

从VBS错误运行EXE

来自分类Dev

无法运行.exe文件

Related 相关文章

  1. 1

    Process.Start()的exe无法正常工作

  2. 2

    使用-Verb RunAs通过Start-Process运行cmd.exe,然后以管理员身份自动运行命令

  3. 3

    Process.Start(“ Excel.exe”)立即退出

  4. 4

    没有“ .exe”扩展名的Process.Start失败

  5. 5

    在IIS中运行时,Process.Start cmd.exe不会运行作为参数传递的cmd文件

  6. 6

    尝试使用Process.Start()以.txt文件作为参数打开.exe文件

  7. 7

    Process.Start()不启动.exe文件(手动运行时有效)

  8. 8

    如何使用 Python 杀死运行 exe 的 Windows

  9. 9

    start.exe如何工作?

  10. 10

    Process.Start()使.exe文件闪现打开,然后立即再次关闭

  11. 11

    通过Process.start将大字符串内容作为参数传递给exe

  12. 12

    如何在System.Diagnostics.Process.Start中将凭据/参数传递给exe

  13. 13

    VB.net:从Process.Start(...)调用时exe文件无法正常工作

  14. 14

    从 C# 中的 Process.Start 启动 cmd.exe 时,无法识别 Telnet 命令

  15. 15

    使用qprocess运行.exe

  16. 16

    Windows:如何获取启动工具来覆盖本地start.exe?

  17. 17

    使用 Ant 通过 cmd.exe“start”命令启动 Java 程序

  18. 18

    在.net中使用start.process运行R脚本

  19. 19

    使用Docker在Windows容器中运行exe文件

  20. 20

    我怎么知道编译是否成功或是否由于process.start()和devenv.exe而失败?

  21. 21

    使用Process.Start()和Windows Task Scheduler的异常

  22. 22

    Windows 10中缺少运行exe

  23. 23

    无法在Windows XP上运行Python EXE

  24. 24

    Cygwin 生成的 .exe 不直接从 Windows 运行

  25. 25

    .exe不在C#中使用Process从其原始目录运行

  26. 26

    以系统帐户运行exe

  27. 27

    从bat文件运行exe

  28. 28

    从VBS错误运行EXE

  29. 29

    无法运行.exe文件

热门标签

归档