0
votes

I'm trying to get Directory SourceDir expanded in my custom action.

My current work looks like this...

<CustomAction Id="CopyShortcutBack" Directory="APPLICATIONFOLDER" 
          Execute="commit" Impersonate="yes" Return="ignore" 
ExeCommand='cmd.exe /k copy "[APPLICATIONFOLDER]MikeySourceToExcelShortcut.lnk" &quot;\&quot;[SourceDir] \&quot;&quot; ' 
              />

The """ and "\&quot" are attempts to make it work after reading this question in stackoverflow... Not able to send Wix SourceDir path with spaces to custom action ExeCommand

However, nothing works. SourceDir doesn't get expanded with or without any combination of quotes around it. Note that my ExeCommand also includes [APPLICATIONFOLDER], which IS being expanded.

The command that wix runs, which I get via wmic in another open cmd.exe is...

cmd.exe /k copy "C:\Users\Mikey\AppData\Local\Apps\Mikey\Personal\Shortcut Test\MikeySourceToExcelShortcut.lnk" "\" \"" 

Note also that the expansion of [APPLICATIONFOLDER] does have a space in it, so I wouldn't suspect that spaces are the problem inside [SourceDir].

A bit more code out of my .wsx file if it's relevant. I commented some of my failed attempts...

   <Shortcut Id="MikeySourceToExcelShortcut"
            Name="MikeySourceToExcelShortcut"
            Description="For finding the installation directory"
            Target="[APPLICATIONFOLDER]"
            WorkingDirectory="SourceDir"/>


</Component>


<!--
The simple way I think it should be...
          ExeCommand='cmd.exe /k copy "[APPLICATIONFOLDER]MikeySourceToExcelShortcut.lnk" "[SourceDir]" ' 



ExeCommand='cmd.exe /k copy "[APPLICATIONFOLDER]MikeySourceToExcelShortcut.lnk" "&quot;[SourceDir]&quot;" ' 
gave...
cmd.exe /k copy "C:\Users\Mikey\AppData\Local\Apps\Mikey\Personal\Shortcut Test\MikeySourceToExcelShortcut.lnk" """" 


ExeCommand='cmd.exe /k copy "[APPLICATIONFOLDER]MikeySourceToExcelShortcut.lnk" "\&quot;[SourceDir]\&quot;" ' 
gave...
cmd.exe /k copy "C:\Users\Mikey\AppData\Local\Apps\Mikey\Personal\Shortcut Test\MikeySourceToExcelShortcut.lnk" "\"\"" 

ExeCommand='cmd.exe /k copy "[APPLICATIONFOLDER]MikeySourceToExcelShortcut.lnk" &quot;\&quot; [SourceDir]\&quot;&quot; ' 
gave...
cmd.exe /k copy "C:\Users\Mikey\AppData\Local\Apps\Mikey\Personal\Shortcut Test\MikeySourceToExcelShortcut.lnk" "\"\"" 


ExeCommand='cmd.exe /k copy "[APPLICATIONFOLDER]MikeySourceToExcelShortcut.lnk" &quot;\&quot;[SourceDir] \&quot;&quot; ' 
gave...
cmd.exe /k copy "C:\Users\Mikey\AppData\Local\Apps\Mikey\Personal\Shortcut Test\MikeySourceToExcelShortcut.lnk" "\" \"" 
-->

<CustomAction Id="CopyShortcutBack" Directory="APPLICATIONFOLDER" 
              Execute="commit" Impersonate="yes" Return="ignore" 
ExeCommand='cmd.exe /k copy "[APPLICATIONFOLDER]MikeySourceToExcelShortcut.lnk" &quot;\&quot;[SourceDir] \&quot;&quot; ' 
              />

<InstallExecuteSequence>
  <Custom Action="CopyShortcutBack" After="InstallInitialize" />
</InstallExecuteSequence>

Note that the shorcut itself has WorkingDirectory set to "SourceDir" and this IS ALSO WORKING, i.e. SourceDir is being expanded here.

I will welcome any ideas to get this working. I don't care if I have to create another property to expand SourceDir and then reference that instead.

BTW I also initially tried just plonking the shortcut directly into SourceDir via the Directory attribute. It didn't work unfortunately. It would have been so good if that worked and then I could have bypassed all this custom action stuff. It's looking suspiciously like Microsoft are disallowing the functionality that I'm trying to achieve (putting a shortcut back into my installation directory).

1

1 Answers

0
votes

Well I found an element called ResolveSource...

<ResolveSource Before="CostFinalize" Suppress="no" />

I found this link after I found the answer.
Why I am getting blank value for SourceDir in a managed Custom Action in WIX?

For some reason when I don't know the solution I find all the threads that don't work on google. Only after I've worked it out do I find other threads with the correct solution. Very mysterious. It's happening with other problems too.