简体   繁体   English

Process.Start() 在某些计算机上无法正常工作

[英]Process.Start() does not work properly on some computers

I have a program where I run some .msi files.我有一个运行一些 .msi 文件的程序。 This program downloads some files from our website and runs the .msi file.该程序从我们的网站下载一些文件并运行 .msi 文件。 When I run the code as below, it runs smoothly on most computers and installs the setup, but on some computers it shows the windows installer information screen.当我运行如下代码时,它可以在大多数计算机上顺利运行并安装设置,但在某些计算机上它会显示 Windows 安装程序信息屏幕。 When I open the project with VisualStudio on the same computer, it still works without any problems.当我在同一台计算机上使用 VisualStudio 打开项目时,它仍然可以正常工作。 I am using WiX Setup as setup builder.我正在使用 WiX Setup 作为设置生成器。 Could you please help if you have any idea about the cause of the problem?如果您对问题的原因有任何想法,能否提供帮助?

Summary概括

Case 1: The program is run with visual studio and the code below works without any problems.案例1:该程序使用visual studio运行,下面的代码没有任何问题。

Case 2 : I am setting up the program with the WiX setup.案例 2:我正在使用 WiX 设置程序设置程序。 In this case some will work on most computers.在这种情况下,有些可以在大多数计算机上工作。 In the first case, it does not work on the working computer.在第一种情况下,它在工作计算机上不起作用。

Case 3: If the setup is run manually by the user, not with the code below, it works without any problems.案例 3:如果设置是由用户手动运行的,而不是使用下面的代码,它可以正常工作。

 Process p = new Process();
 p.EnableRaisingEvents = true;
 p.Exited += ProcessExit;
 p.StartInfo.FileName = "msiexec";
 p.StartInfo.Arguments = string.Format("{0} {1}", "/i", _msiReadPath);
 p.StartInfo.UseShellExecute = true;
 p.Start();

Not : Thinking that the problem might be with the WiX installer, I created a new setup with the Setup Project.不是:考虑到问题可能出在 WiX 安装程序上,我使用 Setup Project 创建了一个新设置。 The same problem persists.同样的问题仍然存在。 On computers with this problem, it gives a warning that it may be infected during installation with Setup Project.在有此问题的计算机上,它会发出警告,表明它可能在安装安装项目期间被感染。 Could the root cause of the problem be the Windows installer?问题的根本原因可能是 Windows 安装程序吗?

Additional Corrections and Notes:其他更正和注释:

The experiences on the computers I've had problems with are as follows.我遇到问题的计算机上的经验如下。

I'm installing my program with the setup that creates it with WiX.我正在使用使用 WiX 创建它的设置来安装我的程序。 Then I run the installation process ( Process ) in the program.然后我在程序中运行安装过程( Process )。 It works but the installer /option screen is displayed.它可以工作,但会显示安装程序/选项屏幕。

I am running the .exe in the Debug folder compiled with Visual Studio on the same computer.我在同一台计算机上使用 Visual Studio 编译的 Debug 文件夹中运行 .exe。 The process runs smoothly and the installation of the .msi file begins.该过程运行顺利,并开始安装 .msi 文件。 I re-added the WiX setup codes below.我在下面重新添加了 WiX 设置代码。

        <Product Id="*" Name="My Installer" Language="1033" Version="!(bind.FileVersion.MyInstaller.exe)" Manufacturer="xxxxx" UpgradeCode="14bc5e0c-6535-4488-a6d8-0de89123aef1">
        <Package InstallerVersion="200" InstallPrivileges="elevated" AdminImage="yes" Compressed="yes" InstallScope="perMachine" />

    <Property Id="MSIUSEREALADMINDETECTION" Value="1" />
    <Property Id="REINSTALLMODE" Value="amus" />
    <MajorUpgrade AllowSameVersionUpgrades="yes" DowngradeErrorMessage="A newer version of [ProductName] is already installed." />

    <Icon Id="icon.ico" SourceFile="$(var.ProjectDir)setupIcon.ico" />
    <Property Id="ARPPRODUCTICON" Value="icon.ico" />
    <WixVariable Id="WixUILicenseRtf" Value="$(var.ProjectDir)\license.rtf" />

     <Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER" />
    <UIRef Id="WixUI_InstallDir" />

    <MediaTemplate />

    <SetProperty Id="ARPINSTALLLOCATION" Value="[INSTALLFOLDER]" After="CostFinalize" />

        <Feature Id="ProductFeature" Title="My Installer" Level="1">
            <ComponentGroupRef Id="ProductComponents" />
            <ComponentGroupRef Id="tr_TR_files" />
            <ComponentGroupRef Id="ProgramFilesFolder_files" />
            <ComponentGroupRef Id="uz_Latn_UZ_files" />
            <ComponentGroupRef Id="ru_ru_files" />
            <ComponentGroupRef Id="Ru_files" />
            <ComponentGroupRef Id="pt_BR_files" />
            <ComponentGroupRef Id="pt_files" />
            <ComponentGroupRef Id="fr_FR_files" />
            <ComponentGroupRef Id="de_files" />
            <ComponentGroupRef Id="cs_CZ_files" />
            <ComponentGroupRef Id="cs_files" />
            <ComponentGroupRef Id="ar_DZ_files" />
            <ComponentGroupRef Id="en_US_files" />
            <ComponentGroupRef Id="fr_files" />
      <ComponentRef Id="ApplicationShortcut" />
      <ComponentRef Id="ApplicationShortcutDesktop" />
        </Feature>
    </Product>

    <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
                <Directory Id="INSTALLFOLDER" Name="My Installer">
                <Directory Id="ar_DZ" Name="ar-DZ" />
                <Directory Id="cs" Name="cs" />
                <Directory Id="cs_CZ" Name="cs-CZ" />
                <Directory Id="de" Name="de" />
                <Directory Id="en_US" Name="en-US" />
                <Directory Id="fr" Name="fr" />
                <Directory Id="fr_FR" Name="fr-FR" />
                <Directory Id="pt" Name="pt" />
                <Directory Id="pt_BR" Name="pt-BR" />
                <Directory Id="Ru" Name="Ru" />
                <Directory Id="ru_ru" Name="ru-ru" />
                <Directory Id="tr_TR" Name="tr-TR" />
                <Directory Id="uz_Latn_UZ" Name="uz-Latn-UZ" />
            </Directory>
      </Directory>
      <Directory Id="ProgramMenuFolder">
        <Directory Id="ApplicationProgramsFolder" Name="My Installer" />
      </Directory>
      <Directory Id="DesktopFolder" Name="Desktop" />
        </Directory>
    </Fragment>

   <Fragment>
    <DirectoryRef Id="ApplicationProgramsFolder">
      <Component Id="ApplicationShortcut" Guid="9bd13330-6540-406f-a3a8-d7f7c69ae7f9">
        <Shortcut Id="ApplicationStartMenuShortcut" Name="My Installer" Description="My Installer" Target="[INSTALLFOLDER]My Installer.exe" WorkingDirectory="INSTALLFOLDER" />
        <RemoveFolder Id="RemoveApplicationProgramsFolder" Directory="ApplicationProgramsFolder" On="uninstall" />
        <RegistryValue Root="HKCU" Key="Software\My Installer" Name="installed" Type="integer" Value="1" KeyPath="yes" />
      </Component>
    </DirectoryRef>
    <DirectoryRef Id="DesktopFolder">
      <Component Id="ApplicationShortcutDesktop" Guid="cde1e030-eb64-49a5-b7b8-400b379c2d1a">
        <Shortcut Id="ApplicationDesktopShortcut" Name="My Installer" Description="My Installer" Target="[INSTALLFOLDER]My Installer.exe" WorkingDirectory="INSTALLFOLDER" />
        <RemoveFolder Id="RemoveDesktopFolder" Directory="DesktopFolder" On="uninstall" />
        <RegistryValue Root="HKCU" Key="Software\My Installer" Name="installed" Type="integer" Value="1" KeyPath="yes" />
      </Component>
    </DirectoryRef>
  </Fragment>

Note 2: If I replace the .exe in the Debug folder with the exe where the program is installed, it works properly.注意2:如果我将Debug文件夹中的.exe替换为安装程序的exe,它可以正常工作。 My guess is WiX Setup is having a problem retrieving the .exe.我的猜测是 WiX 安装程序在检索 .exe 时遇到问题。

Answered here: invoking MSIEXEC within a Process fails在这里回答: 在进程中调用 MSIEXEC 失败

Apparently the issue will go away if you "digitally sign the MSI with a valid certificate."显然,如果您“使用有效证书对 MSI 进行数字签名”,问题就会消失。

The reason for this user dialog might be:此用户对话框的原因可能是:

https://www.trendmicro.com/en_us/research/18/b/attack-using-windows-installer-msiexec-exe-leads-lokibot.html https://www.trendmicro.com/en_us/research/18/b/attack-using-windows-installer-msiexec-exe-leads-lokibot.html

Where the exploit method is very similar to what you are doing.漏洞利用方法与您正在执行的操作非常相似。

Additionally according to: C# Silent installation of msi does not work另外根据: C# Silent installation of msi doesn't work

You need to run the process with elevated privileges as well.您还需要以提升的权限运行该进程。

startInfo.Verb = "runas"; startInfo.Verb = "runas";

Adapted from other answers example:改编自其他答案示例:

string winDir = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
ProcessStartInfo startInfo = new ProcessStartInfo(Path.Combine(winDir, @"System32\msiexec.exe"), $"/i {_msiReadPath} /quiet /qn /norestart ALLUSERS=1");
startInfo.Verb = "runas";
startInfo.UseShellExecute = true;
Process.Start(startInfo);

Try to run the msiexec as a command:尝试将msiexec作为命令运行:

var startInfo = new ProcessStartInfo()
{
  FileName = "cmd.exe",
  Arguments = $"/c \"msiexec /i {fileName}\"",
  UseShellExecute = false,
  CreateNoWindow = true
};

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

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