[英]Process.Start() does not work properly on some computers
我有一個運行一些 .msi 文件的程序。 該程序從我們的網站下載一些文件並運行 .msi 文件。 當我運行如下代碼時,它可以在大多數計算機上順利運行並安裝設置,但在某些計算機上它會顯示 Windows 安裝程序信息屏幕。 當我在同一台計算機上使用 VisualStudio 打開項目時,它仍然可以正常工作。 我正在使用 WiX Setup 作為設置生成器。 如果您對問題的原因有任何想法,能否提供幫助?
概括
案例1:該程序使用visual studio運行,下面的代碼沒有任何問題。
案例 2:我正在使用 WiX 設置程序設置程序。 在這種情況下,有些可以在大多數計算機上工作。 在第一種情況下,它在工作計算機上不起作用。
案例 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();
不是:考慮到問題可能出在 WiX 安裝程序上,我使用 Setup Project 創建了一個新設置。 同樣的問題仍然存在。 在有此問題的計算機上,它會發出警告,表明它可能在安裝安裝項目期間被感染。 問題的根本原因可能是 Windows 安裝程序嗎?
其他更正和注釋:
我遇到問題的計算機上的經驗如下。
我正在使用使用 WiX 創建它的設置來安裝我的程序。 然后我在程序中運行安裝過程( Process
)。 它可以工作,但會顯示安裝程序/選項屏幕。
我在同一台計算機上使用 Visual Studio 編譯的 Debug 文件夾中運行 .exe。 該過程運行順利,並開始安裝 .msi 文件。 我在下面重新添加了 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>
注意2:如果我將Debug文件夾中的.exe替換為安裝程序的exe,它可以正常工作。 我的猜測是 WiX 安裝程序在檢索 .exe 時遇到問題。
在這里回答: 在進程中調用 MSIEXEC 失敗
顯然,如果您“使用有效證書對 MSI 進行數字簽名”,問題就會消失。
此用戶對話框的原因可能是:
漏洞利用方法與您正在執行的操作非常相似。
另外根據: C# Silent installation of msi doesn't work
您還需要以提升的權限運行該進程。
startInfo.Verb = "runas";
改編自其他答案示例:
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);
嘗試將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.