Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a desktop shortcut for a Windows 10 Universal app using powershell?

Tags:

powershell

uwp

I have a UWP app I created and want to use powershell to create a shortcut on the desktop.

Creating a shortcut is easy for an exe

$TargetFile =  "\Path\To\MyProgram.exe"
$ShortcutFile = "$env:USERPROFILE\Desktop\MyShortcut.lnk"
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
$Shortcut.TargetPath = $TargetFile
$Shortcut.Save()

But I'm struggling with what to use as the Target for the Universal apps.. I also know I can easily create a shortcut to an app manually but for this purpose, it needs to be done with PowerShell.. any ideas?

like image 824
Pete Avatar asked Jul 13 '16 18:07

Pete


2 Answers

Creating shortcut for UWP app is a different story from classic desktop. You can refer to my another answer Where linked UWP tile?

To create a shortcut of an UWP app on the desktop using powershell, you can for example code like this:

$TargetFile =  "C:\Windows\explorer.exe"
$ShortcutFile = "$env:USERPROFILE\Desktop\MyShortcut.lnk"
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
$Shortcut.Arguments="shell:AppsFolder\Microsoft.SDKSamples.AdventureWorks.CS_8wekyb3d8bbwe!App"
$Shortcut.TargetPath = $TargetFile
$Shortcut.Save()

You can find the AppUserModelId using the method in the link provided by @TessellatingHeckler, and replace the Microsoft.SDKSamples.AdventureWorks.CS_8wekyb3d8bbwe!App in the code with your desired AppUserModelId.

like image 76
Grace Feng Avatar answered Nov 15 '22 10:11

Grace Feng


To prevent your shortcut from having the standard Explorer icon. Change the $Shortcut.TargetPath like this :

$TargetPath =  "shell:AppsFolder\Microsoft.Windows.Cortana_cw5n1h2txyewy!CortanaUi"
$ShortcutFile = "$Home\Desktop\Cortana.lnk"
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
$Shortcut.TargetPath = $TargetPath
$Shortcut.Save()

This way the shortcut will have the same icon as the application.

You can also create a shortcut *.url via URI (if the application in question supports it) (https://docs.microsoft.com/en-us/windows/uwp/launch-resume/launch-default-app) :

$TargetPath =  "ms-cortana:"
$ShortcutFile = "$Home\Desktop\Cortana.url"
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
$Shortcut.TargetPath = $TargetPath
$Shortcut.Save()
like image 27
ShEp Avatar answered Nov 15 '22 10:11

ShEp