简体   繁体   中英

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

I have a program where I run some .msi files. This program downloads some files from our website and runs the .msi file. 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. When I open the project with VisualStudio on the same computer, it still works without any problems. I am using WiX Setup as setup builder. 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.

Case 2 : I am setting up the program with the WiX setup. 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.

 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. 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?

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. Then I run the installation process ( Process ) in the program. 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. The process runs smoothly and the installation of the .msi file begins. I re-added the WiX setup codes below.

        <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. My guess is WiX Setup is having a problem retrieving the .exe.

Answered here: invoking MSIEXEC within a Process fails

Apparently the issue will go away if you "digitally sign the MSI with a valid certificate."

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

Where the exploit method is very similar to what you are doing.

Additionally according to: C# Silent installation of msi does not work

You need to run the process with elevated privileges as well.

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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