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

后端 未结 4 1183
情话喂你
情话喂你 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()
    
    0 讨论(0)
  • 2021-01-14 15:11

    I don't remember where I got this code from, but it's the best I know for finding a path ...

    Powershell

    $installedapps = get-AppxPackage
    foreach ($app in $installedapps)
    {
        foreach ($id in (Get-AppxPackageManifest $app).package.applications.application.id)
        {
            $line = $app.Name + " = " + $app.packagefamilyname + "!" + $id
            echo $line
        }
    }
    

    ... and there is an addition for this How to avoid error when Get-AppxPackageManifest not found

    0 讨论(0)
  • 2021-01-14 15:17

    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.

    0 讨论(0)
  • 2021-01-14 15:23

    To determine the correct TargetPath https://www.tenforums.com/software-apps/57000-method-open-any-windows-10-apps-command-line.html documents the required steps:

    List all applications via Powershell: get-appxpackage > %TEMP%\application_list.txt

    Open list: notepad %TEMP%\application_list.txt

    Find the PackageFamilyName for your app and navigate to the application's InstallLocation using Windows Explorer

    Opening the AppxManifest.xml shows the Application ID: <Application Id="Microsoft.WinDbg.DbgSrv64" for the executable.

    Combine the PackageFamilyName!ApplicationID to form your TargetPath

    Microsoft.WinDbg_8wekyb3d8bbwe!Microsoft.WinDbg.DbgSrv64 for WinDbg Preview for instance.

    0 讨论(0)
提交回复
热议问题