我正在使用 Windows Installer XML 工具包创建安装程序 msi 文件。安装创建的 msi 文件时,位于 ProgramMenuFolder 文件夹下的快捷方式会导致仅管理员用户的快捷方式。如何让安装程序在所有用户配置文件下创建快捷方式,以便机器上的每个人都有快捷方式?
5 回答
在Package 元素中,添加如下所示的 InstallScope 属性:
InstallScope='perMachine'
基于 WIX 教程http://www.tramontana.co.hu/wix/lesson1.php中的 SampleFirst.wxs ,我更改了两部分。
首先,添加属性 ALLUERS = 1 ""。正如其他人所指出的那样,这将安装所有用户配置文件的快捷方式。
其次,将组件“ProgramMenuDir”的注册表值的根更改为 HKMU。安装程序将根据 ALLUSERS 属性决定在安装时是否应使用 HKLM(本地计算机)或 HKCU(当前用户)。
然后,您应该能够添加对话框来修改 ALLUSERS 属性,并相应地更改注册表根。
<?xml version="1.0" encoding="utf-8"?>
<!-- Original Source available at "http://www.tramontana.co.hu/wix/download.php?file=samples/samplefirst.zip&type=application/zip"
This version has been modified for a local machine install (all users) vs a user install-->
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Name="Foobar 1.0" Id="YOURGUID-CD32-4B20-BB4F-58A5C3B21A7C" UpgradeCode="YOURGUID-EDCE-42A2-9DA2-59FB08AC4FA6" Language="1033" Codepage="1252" Version="1.0.0" Manufacturer="Acme Ltd.">
<Package Id="*" Keywords="Installer" Description="Acme's Foobar 1.0 Installer" Comments="Foobar is a registered trademark of Acme Ltd." Manufacturer="Acme Ltd." InstallerVersion="100" Languages="1033" Compressed="yes" SummaryCodepage="1252" />
<Media Id="1" Cabinet="Sample.cab" EmbedCab="yes" DiskPrompt="CD-ROM #1" />
<Property Id="DiskPrompt" Value="Acme's Foobar 1.0 Installation [1]" />
<Property Id="ALLUSERS" Value="1" />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder" Name="PFiles">
<Directory Id="Acme" Name="Acme">
<Directory Id="INSTALLDIR" Name="Foobar 1.0">
<Component Id="MainExecutable" Guid="YOURGUID-2191-4A98-806B-2554B0DD8FC3">
<File Id="FoobarEXE" Name="FoobarAppl10.exe" DiskId="1" Source="FoobarAppl10.exe" KeyPath="yes">
<Shortcut Id="startmenuFoobar10" Directory="ProgramMenuDir" Name="Foobar 1.0" WorkingDirectory="INSTALLDIR" Icon="Foobar10.exe" IconIndex="0" Advertise="yes" />
<Shortcut Id="desktopFoobar10" Directory="DesktopFolder" Name="Foobar 1.0" WorkingDirectory="INSTALLDIR" Icon="Foobar10.exe" IconIndex="0" Advertise="yes" />
</File>
</Component>
<Component Id="HelperLibrary" Guid="YOURGUID-7BA7-4BD1-90B9-C0DFC21674B1">
<File Id="HelperDLL" Name="Helper.dll" DiskId="1" Source="Helper.dll" KeyPath="yes" />
</Component>
<Component Id="Manual" Guid="YOURGUID-F60A-48D6-83FD-44ED01AA579A">
<File Id="Manual" Name="Manual.pdf" DiskId="1" Source="Manual.pdf" KeyPath="yes">
<Shortcut Id="startmenuManual" Directory="ProgramMenuDir" Name="Instruction Manual" Advertise="yes" />
</File>
</Component>
</Directory>
</Directory>
</Directory>
<Directory Id="ProgramMenuFolder" Name="Programs">
<Directory Id="ProgramMenuDir" Name="Foobar 1.0">
<Component Id="ProgramMenuDir" Guid="YOURGUID-2D4F-443F-9ADA-563DB3C1581F">
<RemoveFolder Id="ProgramMenuDir" On="uninstall" />
<RegistryValue Root="HKMU" Key="Software\[Manufacturer]\[ProductName]" Type="string" Value="" KeyPath="yes" />
</Component>
</Directory>
</Directory>
<Directory Id="DesktopFolder" Name="Desktop" />
</Directory>
<Feature Id="Complete" Level="1">
<ComponentRef Id="MainExecutable" />
<ComponentRef Id="HelperLibrary" />
<ComponentRef Id="Manual" />
<ComponentRef Id="ProgramMenuDir" />
</Feature>
<Icon Id="Foobar10.exe" SourceFile="FoobarAppl10.exe" />
<UI />
</Product>
</Wix>
Stuart Preston 的博客很好地描述了如何做到这一点:
为“所有用户”安装快捷方式(通过 Wayback Machine)
编辑:
大纲是:
在您的 .wxs 文件中,包括以下内容:
<Property Id="ALLUSERS"><![CDATA[2]]></Property>
这将预设一个属性,该属性模仿为您的安装选择“所有用户”而不是“仅我”的行为。您还需要一个类似于以下的目录结构:
<Directory Id='ProgramMenuFolder' Name='PMenu' LongName='Programs'> <Directory Id='MyProductShortcutDir' Name='MyPMenu' LongName='MyProduct' /> </Directory>
最后,您的快捷方式应位于“文件”元素中,如下所示:
<File Id="MyProduct.File0" LongName="MyProduct.exe" Name="MYPROD_1.EXE" src="c:\MyProductSourceFolder\MyProduct.exe" > <Shortcut Id="MyProduct.Shortcut" Directory="MyProductShortcutDir" Name="MPSCUT" LongName="My Product Shortcut" /> </File>
Bob Arnson有一篇博客文章介绍了如何在 Wix 中设置用户与机器。
快速的答案是将 Package 元素的 InstallScope 属性设置为“perMachine”。
简单地定义 ALLUSERS=1 来强制每台机器安装。
<Property Id="ALLUSERS"><![CDATA[1]]></Property>