How to set the Icon path of a file or shortcut to a path containing a dynamic environment variable, in particular the current directory %cd%.
The problem is to set a custom (non-system) icon for a file and that icon remains used on other computers. Both the file and the icon would be shipped in a .zip. When the .zip is uncompressed on other computers, the file should be displayed with the custom icon.
I’m stuck because Windows needs an absolute path and this path changes when the .zip is uncompressed on another computer (with a different absolute location).
I’ve tried, without success, through the GUI Properties window or with PowerShell scripts like
$wshshell = New-Object -ComObject WScript.Shell
$lnk = $wshshell.CreateShortcut("c:\TheFolder\ASubFolder\nameOfMyShortcut.lnk")
$lnk.TargetPath = "%windir%\system32\cmd.exe /c start \"\" \"Includes\myApplication.exe\""
$lnk.IconLocation = "%cd%\Includes\myApplication.ico"
#$lnk.IconLocation = ".\Includes\myApplication.ico"
$lnk.Save()
You can that there’s a trick to make the TargetPath unsensitive to the absolute location of the package folder.
The question is about the how to set the IconLocation path variable relative, both tentatives doesn’t work:
$lnk.IconLocation = ".\Includes\myApplication.ico"
or
$lnk.IconLocation = "%cd%\Includes\myApplication.ico"
As I understand, the environment variable %cd% is dynamical, Windows does not like it.
The way the problem was solved is the following: Create launcher with C# (or a static binary) that do not requires shipping dll in the root folder of the package. The launcher starts the dynamic binary .exe that is located in the resource folder.