1

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.

Ozgur Saklanmaz
  • 528
  • 3
  • 17
  • Does the user have enough permissions to install software and access the packages? – Luaan May 13 '22 at 13:06
  • What do you mean by permissions? When I run it by double-clicking the .msi file on the same computer, it still performs the installation without any problems. I think you have permissions from here. – Ozgur Saklanmaz May 13 '22 at 13:08
  • Sounds like a security program (Windows Defender?) might be blocking it. – Matthew Watson May 13 '22 at 13:27
  • @MatthewWatson The problem persists even with the firewall turned off. – Ozgur Saklanmaz May 13 '22 at 13:28
  • @OzgurSaklanmaz A firewall blocks/permits network connections. This looks like an antivirus issue. It has nothing to do with firewall. – spender May 13 '22 at 13:29
  • @spender There is no third party antivirus program installed on the computers. So, what could be the reason for not running .msi from within the application, but running it manually by double-clicking it? Tried running as administrator. – Ozgur Saklanmaz May 13 '22 at 13:32
  • @OzgurSaklanmaz "it gives a warning that it may be infected during installation with Setup Project" That sounds like an antivirus to me – spender May 13 '22 at 13:33
  • @spender windows own warning Virus & threat protection Unauthorized changes blocked .... – Ozgur Saklanmaz May 13 '22 at 13:41
  • @spender Another strange situation is that even if I open an empty project and create a Setup file with the Setup Project, I get the same Virus warning. Thinking that my own computer may be infected with a virus, I created the setup file on a different computer with a fresh installation, still the same situation :) – Ozgur Saklanmaz May 13 '22 at 14:00
  • I do not have the problem with the .exe in the Debug folder created with Visual Studio on the computers where I have the problem. During the setup setup the computer seems to be preventing me from accessing anything. Do you have an idea? @spender – Ozgur Saklanmaz May 16 '22 at 06:58

2 Answers2

2

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);
tcwicks
  • 495
  • 3
  • 11
0

Try to run the msiexec as a command:

var startInfo = new ProcessStartInfo()
{
  FileName = "cmd.exe",
  Arguments = $"/c \"msiexec /i {fileName}\"",
  UseShellExecute = false,
  CreateNoWindow = true
};
Behnam
  • 337
  • 1
  • 6
  • Unfortunately the problem persists. I think the problem is with permissions on the computer. But I don't understand the main reason. I have no idea what permissions it might be related to. – Ozgur Saklanmaz May 13 '22 at 13:57
  • Did you check these Registry entries: `HKLM\Software\Policies\Microsoft\Windows\Installer :: AlwaysInstallElevated = 1` and `HKCU\Software\Policies\Microsoft\Windows\Installer :: AlwaysInstallElevated = 1` – Behnam May 13 '22 at 14:03
  • I'm on my personal computer right now, I couldn't reproduce the problem on my own computer. I'll check it out when I get to the company on Monday. Also, unfortunately, the registry you mentioned does not exist on this computer. – Ozgur Saklanmaz May 13 '22 at 15:19
  • then you should create the entries. https://learn.microsoft.com/en-us/windows/win32/msi/alwaysinstallelevated – Behnam May 13 '22 at 16:20
  • There is no Installer folder in the registry on my computer. Should I do something extra for this? – Ozgur Saklanmaz May 13 '22 at 19:20
  • I do not have the problem with the .exe in the Debug folder created with Visual Studio on the computers where I have the problem. During the setup setup the computer seems to be preventing me from accessing anything. Do you have an idea ? – Ozgur Saklanmaz May 16 '22 at 06:57