最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Setting WorkingDirectory for multiple shortcuts with Wix - Stack Overflow

programmeradmin2浏览0评论

I need to make two shortcuts, both of them to the same executable, but one of them goes on the desktop, while the other goes in the start menu.

The way it is now, the shortcuts are successfully created, and in the right places. They even work correctly, starting up the right process.

But somehow the shortcuts have no working directory set, so they start up the right process with a working directory that defaults to the shortcut's location instead of the executable's location.

<Feature Id="ProductFeature" Title="MyApp Modules" Level="1"
         Display="expand" AllowAdvertise="no" Absent="disallow">
    [...]
    <ComponentGroupRef Id="ExesMyAppCompGrp" />
    [...]
</Feature>

<Fragment>
    <ComponentGroup Id="ExesMyAppCompGrp" Directory="INSTALLFOLDER">
        <Component Guid="{MyGuid}">
            <File KeyPath="yes" Source="..\..\bin\MyApp.exe" />
            <Shortcut Id="DesktopShortcut"
                        Name="MyApp 9"
                        Description="My Application 9"
                        Advertise="yes" 
                        Directory="DesktopFolder"
                        WorkingDirectory="INSTALLFOLDER" />
            <Shortcut Id="MainMenuShortcut"
                        Name="MyApp 9"
                        Description="My Application 9"
                        Advertise="yes" 
                        Directory="DEFAULTMENUDIR"
                        WorkingDirectory="INSTALLFOLDER" />
            
            <File Source="..\..\bin\MyApp.exe.config"/>
            <File Source="..\..\bin\MyApp.pdb"/>
        </Component>
        [...]
    </ComponentGroup>
</Fragment>

The working directory it's supposed to have lies in "INSTALLFOLDER", for which during Installation the value is passed to the MsiPackage by the WixBundle (which gets it from a custom bootstrapper), and then during Uninstallation the value is retrieved from the registry.

The Start Menu subfolder path for the second shortcut is also stored in and retrieved from the registry:

<Property Id="INSTALLFOLDER">
    <RegistrySearch Id='InstallDirProperty' Root='HKLM'
                    Key='SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MyApp\MyApp9'
                    Name='InstallDir' Type='raw' />
</Property>
<Property Id="DEFAULTMENUDIR">
    <RegistrySearch Id='MenuDirProperty' Root='HKLM'
                    Key='SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MyApp\MyApp9'
                    Name='MenuDir' Type='raw' />
</Property>

<Property Id="MENUDIRNAME">
    <RegistrySearch Id='MenuDirNameProperty' Root='HKLM'
                    Key='SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MyApp\MyApp9'
                    Name='MenuDirName' Type='raw' />
</Property>
<Property Id="DesktopFolder"/>

[...]

<Feature Id="StoredFeatures" Level="1" Display="hidden" AllowAdvertise ="no" Absent ="disallow">

    <Component Directory="ProgramMenuFolder"  >
        <RegistryValue Root='HKMU' Key='SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MyApp\MyApp9'
                       Name='MenuDirName' Value='[MENUDIRNAME]'
                       Type='string' KeyPath='yes' />

    </Component>
    <Component Directory="DEFAULTMENUDIR">
        <RegistryValue Root='HKMU' Key='SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MyApp\MyApp9'
                       Name='MenuDir' Value='[DEFAULTMENUDIR]'
                       Type='string' KeyPath='yes' />
        <RemoveFolder Id ='RemoveDefaultMenuDir' On='uninstall' />
    </Component>
    <Component Directory="INSTALLFOLDER">
        <RegistryValue Root='HKLM' Key='SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MyApp\MyApp9'
                       Name='InstallDir' Value='[INSTALLFOLDER]'
                       Type='string' KeyPath='yes' />
    </Component>
</Feature>
[...]
<Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
        <Directory Id="INSTALLFOLDER" Name="MyApp9">
            [...]
        </Directory>
        <Directory Id="ProgramMenuFolder">
            <Directory Id="DEFAULTMENUDIR" Name="MyApp">
            </Directory>
        </Directory>
        <Directory Id="DesktopFolder" Name="Desktop" />
    </Directory>

</Fragment>

Everything seems to install correctly, but the shortcuts that get created have somehow eaten their WorkingDirectory values, leaving them blank when I inspect them.

I've tried to look up the proper syntax; this one is slotting the component directly underneath the Directory component of the desired WorkingDirectory instead of using a ComponentGroup and its Directory attribute.

So I tried moving the Component and its shortcuts directly underneath the INSTALLFOLDER Directory element, but it didn't change the result.

I also tried hardcoding a new property to the desired path and setting that property as the WorkingDirectory, and that did not change the result either.

发布评论

评论列表(0)

  1. 暂无评论