前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >WiX安装选项---开始菜单项

WiX安装选项---开始菜单项

作者头像
张善友
发布2018-01-19 15:52:21
1.2K0
发布2018-01-19 15:52:21
举报
文章被收录于专栏:张善友的专栏

参考文档: How To: Create a Shortcut on the Start Menu,How To: Create an Uninstall Shortcut

制作的安装程序安装后,都要在开始菜单上生成一个应用程序的菜单,通常包括调用应用程序的快速入口和卸载应用程序项。下面取一个例子来看:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="a960cf35-0779-43e8-923b-35638f2bfc42" Name="Minimal" Language="2052" Version="1.0.0.0" Manufacturer="Geffzhang" UpgradeCode="0bf7e020-5bbd-4a06-8e39-e715999edbf5">
    <Package InstallerVersion="200" Compressed="yes" Description="Minimal Windows Installer Sample" Comments="This installer database contains the logic and data required to install Minimal Windows Installer Sample." />
    <Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />
    <Property Id="EnableEV" Value="1">
    </Property>
    
    <Condition Message="你必须有管理员权限才能安装应用程序"><![CDATA[Privileged]]></Condition>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLLOCATION" Name="Minimal">
          <Component Id="Component1" Guid="{1781A625-8ACB-45E7-A8BA-219D81760B2E}">
            <CreateFolder />
            <Environment Id="TestMinVar" Action="set" Part="all" Name="MinEnvVar" Permanent="no" System="yes" Value="8" />
            <File Id="File_Payload" Source="payload.txt" KeyPath="yes" />
          </Component>
          <Directory Id="GAC" Name="GAC">
            <Component Id="RTGACTest" Guid="22887611-B13E-41EE-897C-D78830E68AEB" DiskId="1">
              <!-- Runtime, assembly in GAC -->
              <File Id="F_RT_GACTEST"  LongName="GACTest.dll" Source="..\build\GACTest.dll" KeyPath="yes" Assembly=".net" />
            </Component>
          </Directory>
          <Component Id="DTGACTest" Guid="FB935B7D-D2BD-4B83-A26C-A9376EBA0915" DiskId="1">
            <!--Design-time, private assembly-->
            <File Id="F_DT_GACTest" LongName="GACTest.dll" Source="..\build\GACTest.dll" KeyPath="yes" />
            <Registry Id="R_DT_MyControl_AssemblyFolders" Root="HKLM" Key="SOFTWARE\Microsoft\.NETFramework\AssemblyFolders\[ProductName]" Value="[$DTGACTest]" Type="string" />
          </Component>
        </Directory>
      </Directory>
      
      <Directory Id="ProgramMenuFolder">
        <Directory Id="MinimalStartMenuFolder" Name="Minimal">
          <Component Id="StartMenuFolder" Guid="B3AEC4C4-3F8E-4865-B87A-B750533776B5" >
            <Shortcut Id="ApplicationStartMenuShortcut" 
                      Name="Minimal Test"  Target="[INSTALLLOCATION]payload.txt"
             WorkingDirectory="INSTALLLOCATION"/>
            <Shortcut Id="UninstallProduct"
                  Name="Uninstall Minimal"
                    Description="Uninstalls My Application"
                  Target="[System64Folder]msiexec.exe"
                  Arguments="/x [ProductCode]"/>

            <RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
            <RegistryValue Root="HKCU" Key="Software\Microsoft\MyApplicationName" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
          </Component>
        </Directory>
      </Directory>
    </Directory>    

    <Feature Id="ProductFeature" Title="Minimal" Level="1">
      <ComponentRef Id="Component1" />
      <ComponentRef Id="DTGACTest"/>
      <ComponentRef Id="RTGACTest" />
      <ComponentRef Id="StartMenuFolder"/>
    </Feature>
    
    <Property Id="WIXUI_INSTALLDIR" Value="INSTALLLOCATION" />
    <UIRef Id="WixUI_InstallDir" />
    <UI />
  </Product>
</Wix>

上面例子中开始菜单项的内容是这一段:

代码语言:js
复制
<Directory Id="ProgramMenuFolder">
        <Directory Id="MinimalStartMenuFolder" Name="Minimal">
          <Component Id="StartMenuFolder" Guid="B3AEC4C4-3F8E-4865-B87A-B750533776B5" >
            <Shortcut Id="ApplicationStartMenuShortcut" 
                      Name="Minimal Test"  Target="[INSTALLLOCATION]payload.txt"
             WorkingDirectory="INSTALLLOCATION"/>
            <Shortcut Id="UninstallProduct"
                  Name="Uninstall Minimal"
                    Description="Uninstalls My Application"
                  Target="[System64Folder]msiexec.exe"
                  Arguments="/x [ProductCode]"/>

            <RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
            <RegistryValue Root="HKCU" Key="Software\Microsoft\MyApplicationName" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
          </Component>
        </Directory>
      </Directory>
    </Directory>    

开始菜单项和要安装的应用程序要分开放在不同的Directory里面,ProgramMenuFolder是标准的Windows开始菜单,第二个Directory将是在windows开始菜单下创建的一个菜单项,我们把它命名

为Minimal,菜单的快捷方式包括三个元素:一个是Component 元素是WiX安装元素的原子单位,Component元素下的Shortcut就是快捷菜单项了,RemoveFolder 元素保证在卸载应用程序的时候

做相关的清理工作。上面的例子中有两个快捷方式,一个是Minimal Test,另一个是Uninstall Minimal,这两个就是Windows开始菜单中所看到的菜单项了。

Windows Installer System64Folder 属性在32位的机器上被解析为System32 目录,在64位的机器上被解析为 SysWow64 目录.

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2008-12-20 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档