Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用C进程从子文件夹安装包含多个msi文件的setup.exe程序_C#_Wpf_Process - Fatal编程技术网

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

C# 使用C进程从子文件夹安装包含多个msi文件的setup.exe程序,c#,wpf,process,C#,Wpf,Process,在我的C WPF应用程序中,我想安装另一个程序。另一个程序由一个setup.exe、多个msi文件和一个vcredit.exe组成。我需要启动setup.exe,因为它将一些参数和信息移交给msi文件,并对程序的现有版本使用更新功能。所以我不能直接启动msi文件 programPath = programPath + @"\setup.exe"; Process programsetup = Process.Start(programPath); programsetup.W

在我的C WPF应用程序中,我想安装另一个程序。另一个程序由一个setup.exe、多个msi文件和一个vcredit.exe组成。我需要启动setup.exe,因为它将一些参数和信息移交给msi文件,并对程序的现有版本使用更新功能。所以我不能直接启动msi文件

programPath = programPath + @"\setup.exe";
Process programsetup = Process.Start(programPath);
programsetup.WaitForExit();
文件存储在我的C应用程序的根目录中。我的问题是无法将文件移动到子文件夹中,因为msi文件总是在根目录中搜索,而不是在子文件夹中搜索

现在:

..\myApp\setup.exe ..\myApp\client.msi ..\myApp\host.msi ..\myApp\manager.msi ..\myApp\vcredit.exe 我的问题:如何移动子文件夹中的setup.exe和msi文件并从那里启动它

我想要的是:

..\myApp\toolkit\setup.exe ..\myApp\toolkit\client.msi ..\myApp\toolkit\host.msi ..\myApp\toolkit\manager.msi ..\myApp\toolkit\vcredist.exe
当我这样做时,安装过程中出现错误:..\myApp\client.msi未找到。

此代码将直接启动setup.exe

属性->右键单击打开到Resources.resx->左上角添加现有文件->选择文件

byte[] resourceFile = Properties.Resources.setup;
        string destination = Path.Combine(Path.GetTempPath(), "setup.exe");
        System.IO.File.WriteAllBytes(destination, resourceFile);
        Process.Start(destination);
我已经用ProcessStartInfo.WorkingDirectory解决了这个问题

问题/解决方案:如果您启动一个安装文件,并在安装过程中从同一目录加载一些msi文件,则需要设置WorkingDirectory

代码示例:

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();

但是我得到了同样的错误。上面的代码直接获取文件路径。如果不更改附加文件的路径,则不应出现此类错误。我试过了,对我来说效果很好。你必须分别为每个.exe或.msi执行。对于单个示例,这是正确的。当setup.exe自身加载msi文件时也是如此?或者你的意思是用一个单独的进程启动每个msi文件?谢谢你的回答。它与ProcessStartInfo.WorkingDirectory一起工作。