Skip to content

Instantly share code, notes, and snippets.

@rileyz
Created June 22, 2016 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rileyz/670a3ff47c2b840c02459e6fdc3a8e9d to your computer and use it in GitHub Desktop.
Save rileyz/670a3ff47c2b840c02459e6fdc3a8e9d to your computer and use it in GitHub Desktop.
<#
.SYNOPSIS
Manages a shortcut in the desired location for App-V using the appvve hook.
.DESCRIPTION
Intended Use
Creates or removes a shortcut on the target system with the desired target,
working directory and swicthes.
Example
Action this script using the App-V DeploymentConfig, using the child elements PublishPackage
and/or UnpublishPackage.
The parameters are as follows.
-SourceExe Path to the executable.
-ArgumentsToSourceExe Arguments for the executable, dont forget to add the appve hook.
-DestinationPath Path where the shortcut.lnk file will be created.
-DeploymentConfig Switch to specify creation of shortcut in all users Start menu.
-UserConfig Switch to specify creation of shortcut in users Start menu.
-Remove Switch to remove the shortcut.
* Create shortcut for all users Start menu.
Manage-Shortcut.ps1 -SourceExe "C:\Program Files\App\App.exe" -ArgumentsToSourceExe "/SomeAppSwitchExample /appvve:PackageIdGuid_VersionIdGuid" -DestinationPath "\Microsoft\Windows\Start Menu\Programs\The App Shortcut.lnk" -DeploymentConfig
* Create shortcut users Start menu.
Manage-Shortcut.ps1 -SourceExe "C:\Program Files\App\App.exe" -ArgumentsToSourceExe "/SomeAppSwitchExample /appvve:PackageIdGuid_VersionIdGuid" -DestinationPath "\Microsoft\Windows\Start Menu\Programs\The App Shortcut.lnk" -UserConfig
* Remove shortcut for all users.
Manage-Shortcut.ps1 -DestinationPath "\Microsoft\Windows\Start Menu\Programs\The App Shortcut.lnk" -DeploymentConfig -Remove
* Remove shortcut user profile.
Manage-Shortcut.ps1 -DestinationPath "\Microsoft\Windows\Start Menu\Programs\The App Shortcut.lnk" -UserConfig -Remove
About
I had an issue with Word 2013 add-ons and App-V, where it would prompt an warning it needed
repairing. Even though there was almost no registry or VFS files in the package that could
cause the prompt. I wrote this script to create a shortcut with the appvve hook, as that
seemed to work ok.
See this link for more details.
http://www.appvirtguru.com/viewtopic.php?f=70&t=8509&sid=7fe2d4254bf86549fe401faf0f97f067
Known Defects/Bugs
* No error checking within this script.
Code Snippet Credits
* http://stackoverflow.com/questions/9701840/how-to-create-a-shortcut-using-powershell
Version History
1.0 19/05/2016
Initial release.
Copyright & Intellectual Property
Feel to copy, modify and redistribute, but please pay credit where it is due.
Feed back is welcome, please contact me on LinkedIn.
.LINK
Author:.......http://www.linkedin.com/in/rileylim
Source Code:..https://gist.github.com/rileyz
Article:......http://www.itninja.com/blog/view
.EXAMPLE
Create a shortcut with appvve hook for global publishing via DeploymentConfig.xml.
<PublishPackage>
<Path>PowerShell</Path>
<Arguments>-ExecutionPolicy ByPass -WindowStyle Hidden -File Manage-Shortcut.ps1 -SourceExe "C:\Program Files\App\App.exe" -ArgumentsToSourceExe "/SomeAppSwitchExample /appvve:PackageIdGuid_VersionIdGuid" -DestinationPath "\Microsoft\Windows\Start Menu\Programs\The App Shortcut.lnk" -DeploymentConfig</Arguments>
...
.EXAMPLE
Create a shortcut with appvve hook for user publishing via UserConfig.xml.
<PublishPackage>
<Path>PowerShell</Path>
<Arguments>-ExecutionPolicy ByPass -WindowStyle Hidden -File Manage-Shortcut.ps1 -SourceExe "C:\Program Files\App\App.exe" -ArgumentsToSourceExe "/SomeAppSwitchExample /appvve:PackageIdGuid_VersionIdGuid" -DestinationPath "\Microsoft\Windows\Start Menu\Programs\The App Shortcut.lnk" -UserConfig</Arguments>
...
.EXAMPLE
Remove a shortcut with appvve hook globally published via DeploymentConfig.xml.
<RemovePackage>
<Path>powershell.exe</Path>
<Arguments>-ExecutionPolicy ByPass -File Manage-Shortcut.ps1 -DestinationPath "\Microsoft\Windows\Start Menu\Programs\The App Shortcut.lnk" -DeploymentConfig -Remove</Arguments>
...
.EXAMPLE
Remove a shortcut with appvve hook user published via UserConfig.xml.
<RemovePackage>
<Path>powershell.exe</Path>
<Arguments>-ExecutionPolicy ByPass -File Manage-Shortcut.ps1 -DestinationPath "\Microsoft\Windows\Start Menu\Programs\The App Shortcut.lnk" -UserConfig -Remove</Arguments>
...
#>
Param ([String]$SourceExe,
[String]$ArgumentsToSourceExe,
[Parameter(Mandatory=$True)][String]$DestinationPath,
[Switch]$DeploymentConfig,
[Switch]$UserConfig,
[Switch]$Remove)
# Start of script work ############################################################################
If ($DeploymentConfig -eq $True)
{$DestinationPath = $env:ALLUSERSPROFILE + "$DestinationPath"}
If ($UserConfig -eq $True)
{$DestinationPath = $env:AppData + "$DestinationPath"}
If ($Remove -eq $false)
{$WshShell = New-Object -ComObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($DestinationPath)
$Shortcut.TargetPath = $SourceExe
$Shortcut.Arguments = $ArgumentsToSourceExe
$Shortcut.Save()}
Else{Remove-Item $DestinationPath -Force}
#<<< End of script work >>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment