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

简介:

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

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

<?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>
上面例子中开始菜单项的内容是这一段:

<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 目录.

本文来自云栖社区合作伙伴“doNET跨平台”,了解相关信息可以关注“opendotnet”微信公众号

目录
相关文章
|
16天前
|
Shell
删除右键“在 Visual Studio 中打开”选项
删除右键“在 Visual Studio 中打开”选项
|
3月前
win32编程 -- 系统菜单及右键菜单
win32编程 -- 系统菜单及右键菜单
22 1
|
9月前
|
API
ant.design Table组件点击一个选项框却把所有选项都选中了
ant.design Table组件点击一个选项框却把所有选项都选中了
89 0
ant.design Table组件点击一个选项框却把所有选项都选中了
|
Java Android开发
eclipse修改文件打开的默认样式
1.在当前jsp页面里面,右击——open with——jsp Edit。这样只是设置当前的页面的打开类型,为jsp编辑类型。
67 0
|
iOS开发
Xcode使用 -选中工程文件时Project,target这一栏有时会被覆盖
Xcode使用 -选中工程文件时Project,target这一栏有时会被覆盖
95 0
Xcode使用 -选中工程文件时Project,target这一栏有时会被覆盖
|
IDE 开发工具
phpstorm打开项目不能显示最近文件的解决方法
phpstorm打开项目不能显示最近文件的解决方法
180 0
|
Windows
IntellJ_打开选中的文件所在的文件夹
方法(一)最简单 idea 打开 setting 找到keymap 搜索 show in explorer 右键设置一个快捷键  我一般设置 alt + v 然后点击项目其中一个文件位置 比如我点击一个 hellowworld.class  然后我按 alt +v 就会自己打开他在本地的位置 方法(二)比方法一 详细 MyEclipse中工具栏有个功能,选中项目中的某个文件,单击按钮可以打开此文件(或目录) 在windows资源管理器中的位置。
1166 0
|
C# Windows 区块链