Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions assets/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@
<!-- Default value of Checkbox of starting PowerShell after installation -->
<Property Id="WixShellExecTarget" Value="[$(var.ProductVersionWithName)]pwsh.exe"/>
<CustomAction Id="LaunchApplication" BinaryKey="WixCA" DllEntry="WixShellExec" Impersonate="yes" />
<CustomAction Id="SaveShortcutPath" Property="ShortcutPath" Value="[$ApplicationProgramsMenuShortcut]$(var.ProductSemanticVersionWithNameAndOptionalArchitecture).lnk" />
<CustomAction Id="FixShortcutWorkingDirectory" Script="vbscript" HideTarget="no" Impersonate="no">
shortcutPath = Session.Property("ShortcutPath")
Set fso = CreateObject("Scripting.FileSystemObject")
if (fso.FileExists(shortcutPath)) Then
Set wshShell = CreateObject("WSCript.Shell")
Set shortcut = wshShell.CreateShortcut(shortcutPath)

shortcut.workingdirectory = "%HOMEDRIVE%%HOMEPATH%"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That WIX property translates to this Windows Installer property, which resolves the environment variable at install time. If we put %HOMEDRIVE%%HOMEPATH% into the WIX configuration it creates the shortcut hardcoded to the value for the user who is doing the install.

As far as I can tell there is no way to override this Windows Installer behavior.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it as a WIX property set to %HOMEDRIVE%%HOMEPATH% and Windows Installer still resolves it at install time to a hardcoded path. I also tried various methods of escaping and they all got passed through as literal text that resulted in an invalid working directory (ex [\%]HOMEDRIVE[\%]).

The one other method that did show promise was:

  1. Set an environment variable (ex TempWkDir) to %HOMEDRIVE%%HOMEPATH% (this was set on the target machine outside of the install process)
  2. Create a WIX property with value of the environment variable
  3. Point the shortcut WorkingDirectory attribute to the WIX property

This resulted in %TempWkDir% being resolved to %HOMEDRIVE%%HOMEPATH% at install time and the desired shortcut being created. The problem is I could not find a way to temporarily set that environment variable on the install process's environment. Using WIX's environment settings doesn't update the install process's environment, so the value was not resolved properly during the install.

Also setting up several layers of environment variables and WIX properties that get substituted for each other seems more complicated for future maintenance than just a simple script that explicitly updates the shortcut.

Copy link
Collaborator

@iSazonov iSazonov Jan 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The link above suggests [HOMEDRIVE][HOMEPATH].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those get passed through without being modified, I don't think they're valid properties in MSI: https://msdn.microsoft.com/en-us/library/windows/desktop/aa370905(v=vs.85).aspx

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I see we have to use a script.

I think an user profile root folder is not appropriate work directory - user should create nothing in the directory. What about the user Documents folder?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh? Then why doesn't PowerShell define $Home to be the Documents dir? I put files in the root of my home dir all the time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm open to other folders but I'll leave these notes as well:

  1. %HOMEDRIVE%%HOMEPATH% matches the behavior of both cmd.exe and powershell.exe which will give a consistent user experience
  2. Users can change the value of HomePath (not that I've ever bothered to do this)
  3. Some cloud sync services create folders in the profile directory (OneNote, Google Drive) that may be the preferred location for some people, this puts them at the root of their profile so they can choose which to go in to

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put files in the root of my home dir all the time.

😄 In my enterprise, we warn users of this practice, and even manage to block it as virus suspicious.

I'd reword this arguments:

  1. User can have many workspaces and we can not predict better location.
  2. User shouldn't change HomePath but they can change the shortcut or even better to create new one.
  3. %HOMEDRIVE%%HOMEPATH% looks better for consistency with Unix.

shortcut.save
End If
</CustomAction>
<UI>
<Dialog Id="MyExitDialog" Width="370" Height="270" Title="!(loc.ExitDialog_Title)">
<Control Id="LaunchCheckBox" Type="CheckBox" X="10" Y="243" Width="170" Height="17" Property="LAUNCHAPPONEXIT" Hidden="yes" CheckBoxValue="1" Text="Launch $(env.ProductName)">
Expand Down Expand Up @@ -185,6 +197,12 @@
</Directory>
</Directory>
</Directory>
<InstallExecuteSequence>
<Custom Action="SaveShortcutPath" After="InstallFinalize" />
<Custom Action="FixShortcutWorkingDirectory" After="SaveShortcutPath">
NOT Installed OR NOT REMOVE OR UPGRADINGPRODUCTCODE
</Custom>
</InstallExecuteSequence>
</Product>

<!-- Explorer Context Menu Dialog -->
Expand Down