如何:使用 wix 工具集在 Windows 启动时启动程序? [英] How to : Making a program start on Windows startup with wix toolset?

查看:29
本文介绍了如何:使用 wix 工具集在 Windows 启动时启动程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Hello world"windows 窗体应用程序(在 VS-2013 中创建).
如何使用 WIX 工具集在 Windows 启动时启动应用程序?
必须在 windows7 和 windows8 下工作.
这是我目前拥有的 Product.wxs.

I have simple "Hello world" windows forms application (created in VS-2013).
How to making an aplication start on Windows startup, with WIX Toolset ?
Must work in windows7 and windows8.
This is Product.wxs I have currently.

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*" Name="Installer" Language="1033" Version="1.0.0.0" Manufacturer="DMC" UpgradeCode="808c333f-09f7-45d5-a5ab-ea104c500f2b">
        <Package Id="*" InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
        <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
        <MediaTemplate />
        <Feature Id="ProductFeature" Title="Installer" Level="1">
            <ComponentGroupRef Id="ProductComponents" />
        </Feature>
    </Product>
    <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
                <Directory Id="INSTALLFOLDER" Name="HelloWorld" />
            </Directory>
      <Directory Id="StartupFolder">
      </Directory>
        </Directory>
    </Fragment>
    <Fragment>
        <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
      <Component Guid="{A4744AE7-211C-42A0-887D-1701D242776C}">
        <File Source="$(var.HelloWorld.TargetPath)" KeyPath="yes" />
      </Component>
  </ComponentGroup>
    </Fragment>
</Wix>


感谢您的帮助,但对我来说还不够好.在哪里添加这个标签?我应该创建快捷方式,还是 wix 会为我做?我是否必须包含 wix 的快捷方式,以及如何添加?我是否必须将 .ico 包含到 wix 项目中?我需要逐步解释以理解这一点. Hello World 项目示例的整个 Product.wxs 将是最好的.

我仍然不知道如何用 wix 解决这个问题.我使用了不同的方法:如何在 Windows 启动时运行 C# 应用程序?

推荐答案

我还没有时间在家里的 Wix Directory 项目中测试结构,但是从我的脑海中,目录结构应该看起来有些东西像这样

I haven't had the time to test the structure, in my Wix Directory project at home, but from the top of my head the directory structure should look something like this

<Directory Id="TARGETDIR" Name="SourceDir"> 
  <Directory Id="ProgramFilesFolder"> 
    <Directory Id="INSTALLDIR" .. > 
      <Component ... > 
        <File ... > 
          <Shortcut Id=".." Directory="StartupFolder" ...> 
            <Icon ... /> 
          </Shortcut> 
        </File> 
      </Component> 
    </Directory> 

    <!-- ADD THIS --> 
    <Directory Id="StartupFolder" ...> 
      <Directory Id="MyShortcutFolder" ... /> 
    </Directory> 
  </Directory> 
</Directory> 

** 更新 **

默认情况下,包含目录结构的 Fragment 紧跟在 product 元素之后.

By default, the Fragment containing the Directory structure is right after the product element.

在声明安装所需目录结构的 Fragment 中,将目录引用添加到 windows 下的 Start Up 文件夹中.

In the Fragment that declares the directory structure required for your installation, you will add the directory reference to the Start Up folder under windows.

之后,您必须创建将指示它获取文件并在您作为参考传递的目录(启动文件夹)中创建快捷方式的组件.

After, you must create the component that will instruct it to take a file and create a ShortCut in the directory that you pass as reference (Start Up Folder).

安装程序启动时,会将快捷方式复制到您引用的目录中指定的文件中.

When the installer launches, it will copy the short cut to the file specified in the directory that you referenced.

** 来自您的来源 **

** FROM YOUR SOURCE **

在包含您的产品组件的片段中添加此声明

In the fragment that has your product components add this declaration

<DirectoryRef Id="StartupFolder">
  <Component Id="ApplicationShortCutStartUp" Guid="{BCC2E481-53AF-4690-912D-1051B930B910}">
    <Shortcut Id="AppShortCutStartUp" Name="DMC"
              Description="DMC HELLO"
              Target="[INSTALLDIR][[ NAME OF YOUR EXE]]"
              WorkingDirectory="INSTALLDIR" />


    <RegistryKey Root="HKLM" Key="DMC\HelloWorld" Action="createAndRemoveOnUninstall">
      <RegistryValue Name="ShortCutStartUp" Type="integer" Value="1" KeyPath="yes"  />
    </RegistryKey>        
  </Component>

</DirectoryRef>

在产品下的功能标签中添加对新组件的引用所以现在您的产品声明将如下所示

In the Feature tag under product add the reference to your new component so now your product declaration will look like this

  <Product Id="*" Name="Installer" Language="1033" Version="1.0.0.0" Manufacturer="DMC" UpgradeCode="808c333f-09f7-45d5-a5ab-ea104c500f2b">
    <Package Id="*" InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    <MediaTemplate />
    <Feature Id="ProductFeature" Title="Installer" Level="1">
      <ComponentGroupRef Id="ProductComponents" />
      <ComponentGroupRef Id="ApplicationShortCutStartUp" />
    </Feature>
  </Product>

这会将快捷方式复制到您机器的启动文件夹中.

That will copy a shortcut to your start-up folder for your machine.

调整

这个:

<ComponentGroupRef Id="ApplicationShortCutStartUp" />

应该

<ComponentRef Id="ApplicationShortCutStartUp" />

这个:

<!-- ADD THIS --> 
<Directory Id="StartupFolder" ...> 
  <Directory Id="MyShortcutFolder" ... /> 
</Directory> 

应该是:

<Directory Id="StartupFolder" ...> 
</Directory> 

那应该可以解决你的两个错误

That should fix your two errors

这篇关于如何:使用 wix 工具集在 Windows 启动时启动程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆