如何在 Wix 工具集中识别当前登录用户? [英] How can i identify the current logon user in Wix toolset?

查看:28
本文介绍了如何在 Wix 工具集中识别当前登录用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Wix 构建安装程序,我必须将一个文件放入 Startup 文件夹中.我已经找到了如何构建启动文件夹的路径,但我找不到任何可以识别当前用户的变量.

I'm trying to build an installer with Wix and i have to put a file in the Startup folder. I already found out how to build the path to the startup folder but i can't find any variabile that can identify the current user.

这就是我现在所做的,它可以工作,但带有用户名的部分只需创建一个具有该名称的新目录

推荐答案

启动时运行

通常您会在启动文件夹中放置文件的快捷方式,而不是实际文件.您可以参考内置的 Windows 安装程序属性 StartupFolder,如下面的模型示例所示(以及 Phil 所述).

Run on Startup

Normally you would put a shortcut to a file in the startup folder, and not an actual file. You do so by refering to the built-in Windows Installer Property StartupFolder as shown in the mockup-sample below (and as stated by Phil).

在替代方案领域,有很多方法可以从 Windows 开始安排某些事情.这是什么类型的文件,它有什么作用?如果您有兴趣,可以通过运行 AutoRuns(来自 SysInternals).有一系列令人震惊的可能性(小题大做).

In the realm of alternatives, there are many ways to schedule something to start with Windows. What type of file is this and what does it do? In case you are interested, you can see a number of ways used to start something on login or boot by running AutoRuns (from SysInternals). There is a shocking array of possibilities (small digression).

很多时候,您可以将事情作为服务计划任务来运行,而不是使用其他启动功能.通常为需要连续运行的功能提供服务,为需要不时运行的东西提供计划任务.我认为大多数人都希望避免在登录时运行太多东西 - 如果它们不是真正必要的.我发现启动文件夹笨拙" - 也容易受到用户干扰.

Very often you can run things as services or scheduled tasks, rather than using other startup features. Generally services for features that need to run continuously, and scheduled tasks for stuff that needs to run every now and then. I think most people want to avoid too many things running on login - if they are not really necessary. I find the startup folder "clunky" - and also prone to user interference as well.

这篇 Experts-Exchange 文章 描述了在删除启动文件夹条目后触发自我修复的案例(搜索启动"以找到该部分).

This Experts-Exchange article describes a case when self-repair was triggered after deleting a startup folder entry (search for "startup" to find the section).

坦率地说,我对所描述的场景感到有些惊讶.当一个快捷方式被删除时,它不应轻易自动返回,因为它通常不是其托管组件的关键路径.不过,当您测试 MSI 时要检查一些东西(删除快捷方式,然后直接启动您的应用程序 - 如果有快捷方式可以这样做).如果您发现问题,请告诉我们.

Frankly I am a bit surprised at the described scenario. When a shortcut is deleted, it should not come back automatically easily, since it is generally not the key path of its hosting component. Still, something to check when you test your MSI (delete the shortcut and then launch your app directly - if there is a shortcut to do so). If you see the problem, please let us know.

如果我猜猜到底发生了什么,他们可能已经在快捷方式文件夹中安装了一个实际文件并将其设置为关键路径(这似乎也是您正在尝试做的).然后他们将其置于与广告快捷方式相同的功能层次结构中 - 应用程序的相同功能或顶级功能,或父功能 - 导致在调用广告快捷方式时始终调用自我修复,以及丢失的文件在 Startup 文件夹中检测到,并进行自我修复.

If I were to guess what really happened, they might have installed an actual file into the shortcut folder and set it as the key path (which is what it seems you are trying to do as well). Then they have put this in the same feature hierarchy as an advertised shortcut - the same feature or the top feature of the application, or a parent feature - causing self-repair to always be invoked when the advertised shortcut is invoked, and the missing file is detected in the Startup folder and self-repair ensues.

题外话:题外话,重要的是请检查您的设置!这种问题确实会激怒您的用户 - 其原因往往会躲避他们的支持人员.

这是一个关于如何安装启动文件夹快捷方式的示例.请注意,启动文件夹重定向取决于安装程序是按用户还是按机器安装,如 MSDN 上所述:启动文件夹.

Here is one sample for how to install a shortcut to the Startup folder. Note that the Startup folder redirects depending on whether the setup is installed per-user or per-machine, as documented on MSDN: StartupFolder.

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*" Name="Startup Shortcut" Manufacturer="Someone" Version="0.0.1" 
             Language="1033" UpgradeCode="PUT-GUID-HERE">
        <Package InstallScope="perMachine" Compressed="yes" />
        <Media Id="1" Cabinet="my.cab" EmbedCab="yes" />

        <UIRef Id="WixUI_Mondo" /> <!-- Just include a default setup GUI -->

        <Directory Id="TARGETDIR" Name="SourceDir">

            <Directory Id="ProgramFilesFolder" Name="PFiles">
                <Directory Id="MyCompany" Name="Company">
                    <Directory Id="MyAPP" Name="MyApp">

                        <Component Feature="MyFeature">

                            <File Source="MyApp.exe" />

                            <!-- Set Advertise="no" to avoid advertised shortcut -->
                            <Shortcut Id="MyApp" Directory="StartupFolder" Name="MyApp"
                                      Advertise="yes" />

                        </Component>

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

        <Feature Id="MyFeature" Absent="disallow" />        
        <Property Id="MSIFASTINSTALL" Value="7" /> <!-- Tweak to install faster -->

    </Product>
</Wix>

这篇关于如何在 Wix 工具集中识别当前登录用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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