如何为所有用户安装程序快捷方式?

14

我正在使用Windows Installer XML工具包创建安装程序MSI文件。当安装已创建的MSI文件时,放置在ProgramMenuFolder文件夹下的快捷方式仅适用于管理员用户。我该如何让安装程序在所有用户配置文件下创建快捷方式,以便机器上的每个人都有这个快捷方式?

5个回答

21

Package元素中,添加一个InstallScope属性,如下:

InstallScope='perMachine'

当您这样做时,您就不必担心ALLUSERS属性。将InstallScope设置为“perMachine”会自动将ALLUSERS设置为1。 - Thinko

12

根据WIX教程中的SampleFirst.wxs http://www.tramontana.co.hu/wix/lesson1.php,我对其进行了两处更改。

首先,添加属性ALLUSERS = 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>

谢谢您提供如此详细的例子! - Cabuxa.Mapache
我们如何在创建快捷方式时设置条件? - Ahmed HM

4

Stuart Preston的博客详细介绍了如何完成此操作:

通过Wayback Machine为“所有用户”安装快捷方式

编辑:

简要概述:

In your .wxs file, include the following:

<Property Id="ALLUSERS"><![CDATA[2]]></Property>

This will preset a property which mimics the behaviour of selecting the "All Users" rather than "Just Me" for your installation. You'll need a directory structure similar to the following too:

<Directory Id='ProgramMenuFolder' Name='PMenu' LongName='Programs'>
<Directory Id='MyProductShortcutDir' Name='MyPMenu' LongName='MyProduct' />
</Directory>

Finally, your shortcut should be within a "File" element, as follows:

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

2

Bob Arnson撰写了一篇关于如何在Wix中设置用户和机器的博客文章
简单来说,只需将Package元素的InstallScope属性设置为“perMachine”即可。


0

可以简单地定义ALLUSERS=1来强制进行全局安装。

  <Property Id="ALLUSERS"><![CDATA[1]]></Property>

2
你应该使用 InstallScope='perMachine' 而不是其他。 - Shay Erlichmen
这不是只设置ALLUSERS属性吗?至少文档中是这样指示的。 - saschabeaumont

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接