How can i identify the current logon user in Wix toolset?

拟墨画扇 提交于 2020-07-10 07:57:09

问题


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.

That's what i have done for now and it works but the part with the name of the user just creates a new directory with that name


回答1:


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

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.


Self-Repair and the Startup Folder

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

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.

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.

Digression: a sizeable digression, the important point is to please check this for your setup! This kind of problem really aggravate your users - the cause of it tends to elude their support guys.


Mockup WiX Sample

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>



回答2:


There are a couple of things probably wrong with your idea:

  1. You shouldn't need to build that entire directory tree to get to the StartupFolder because there is already a standard Windows Installer property named StartupFolder. This is already the path to the current user's startup folder so it's not clear why you need the value of LogonUser.

  2. Properties are resolved by placing them in square brackets, so in the general case you'd use [LogonUser], but directory names in the Directory table are not marked as Formatted type, so calling a directory [LogonUser] won't work. You'd need to set another public property to the value of [LogonUser] and then use that property as a directory name. However, I think point 1. may be all you need, and your directory tree isn't clear about your intent.




回答3:


This should be a property set automatically in the installer at run time, LogonUser.



来源:https://stackoverflow.com/questions/50812809/how-can-i-identify-the-current-logon-user-in-wix-toolset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!