简体   繁体   English

使用子文件夹中的 C# 进程安装包含多个 msi 文件的 setup.exe 程序

[英]Installing a program with setup.exe including multiple msi-files using C# process from a subfolder

In my C# WPF application I want to install an other program.在我的C# WPF应用程序中,我想安装其他程序。 The other program consists of a setup.exe, multiple msi files and a vcredist.exe.另一个程序由一个 setup.exe、多个 msi 文件和一个 vcredist.exe 组成。 I need to start the setup.exe because it hands over some parameters and information to the msi files and uses an update functionality for the existing version of the program.我需要启动 setup.exe,因为它会将一些参数和信息移交给 msi 文件,并为程序的现有版本使用更新功能。 So I can't start the msi files directly.所以我不能直接启动msi文件。

programPath = programPath + @"\setup.exe";
Process programsetup = Process.Start(programPath);
programsetup.WaitForExit();

Files are stored in root directory of my C# app.文件存储在我的C#应用程序的根目录中。 My problem is that I can't move the files to an subfolder because the msi files are always searched in the root directory and not in the subfolder.我的问题是我无法将文件移动到子文件夹,因为 msi 文件总是在根目录而不是子文件夹中搜索。

now:现在:

  • ..\myApp\setup.exe ..\myApp\setup.exe
  • ..\myApp\client.msi ..\myApp\client.msi
  • ..\myApp\host.msi ..\myApp\host.msi
  • ..\myApp\manager.msi ..\myApp\manager.msi
  • ..\myApp\vcredist.exe ..\myApp\vcredist.exe

My question: How can I move setup.exe and msi files in a subfolder and start it from there?我的问题:如何将 setup.exe 和 msi 文件移动到子文件夹中并从那里启动?

What I want:我想要的是:

  • ..\myApp\toolkit\setup.exe ..\myApp\toolkit\setup.exe
  • ..\myApp\toolkit\client.msi ..\myApp\toolkit\client.msi
  • ..\myApp\toolkit\host.msi ..\myApp\toolkit\host.msi
  • ..\myApp\toolkit\manager.msi ..\myApp\toolkit\manager.msi
  • ..\myApp\toolkit\vcredist.exe ..\myApp\toolkit\vcredist.exe

Error I get during setup when I do it this way: ..\myApp\client.msi not found.当我这样做时,我在设置过程中遇到错误: ..\myApp\client.msi not found.

This code will directly launch setup.exe.此代码将直接启动 setup.exe。

Properties -> right click Open to Resources.resx -> Top Left Add Existing File -> select the file.属性 -> 右键单击 Open to Resources.resx -> 左上角添加现有文件 -> select 文件。

byte[] resourceFile = Properties.Resources.setup;
        string destination = Path.Combine(Path.GetTempPath(), "setup.exe");
        System.IO.File.WriteAllBytes(destination, resourceFile);
        Process.Start(destination);

I've solved it with ProcessStartInfo.WorkingDirectory .我已经用ProcessStartInfo.WorkingDirectory解决了它。

Problem/Solution: If you start a setup file with Process which loads during installation some msi files from same directory you need to set WorkingDirectory .问题/解决方案:如果您使用Process启动安装文件,该文件在安装期间从同一目录加载一些 msi 文件,您需要设置WorkingDirectory

Code example:代码示例:

string ToolkitExe = myAppPath + @"\myApp\toolkit\setup.exe";
string ToolkitPath = myAppPath + @"\myApp\toolkit\";
ProcessStartInfo startInfo = new ProcessStartInfo(myAppPath + @"\myApp\toolkit\");
startInfo.WorkingDirectory = myAppPath;
Process p = Process.Start(startInfo);
p.WaitForExit();
RunAll();

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

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