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

后端 未结 4 1180
情话喂你
情话喂你 2021-01-14 14:21

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 =  \"\\         


        
4条回答
  •  囚心锁ツ
    2021-01-14 14:59

    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()
    

提交回复
热议问题