如何使用 powershell 为 Windows 10 通用应用程序创建桌面快捷方式? [英] How can I create a desktop shortcut for a Windows 10 Universal app using powershell?

查看:106
本文介绍了如何使用 powershell 为 Windows 10 通用应用程序创建桌面快捷方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个 UWP 应用,想使用 powershell 在桌面上创建快捷方式.

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

为exe创建快捷方式很容易

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

但我正在为通用应用程序的目标使用什么而苦苦挣扎..我也知道我可以轻松地手动创建应用程序的快捷方式,但为此,它需要使用 PowerShell 完成.. 任何想法?

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?

推荐答案

为 UWP 应用创建快捷方式与经典桌面不同.你可以参考我的另一个回答Wherelinked UWP tile?

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

要使用 powershell 在桌面上创建 UWP 应用的快捷方式,您可以使用如下代码:

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

您可以使用@TessellatingHeckler 提供的链接中的方法找到 AppUserModelId,并将代码中的 Microsoft.SDKSamples.AdventureWorks.CS_8wekyb3d8bbwe!App 替换为您想要的 AppUserModelId.

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.

这篇关于如何使用 powershell 为 Windows 10 通用应用程序创建桌面快捷方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆