powershell - 如何使用 powershell 为 Windows 10 通用应用程序创建桌面快捷方式?

标签 powershell uwp

我有一个我创建的 UWP 应用程序,并想使用 powershell 在桌面上创建一个快捷方式。

为 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 来完成。有什么想法吗?

最佳答案

为 UWP 应用创建快捷方式与经典桌面不同。可以引用我的另一个回答Where linked UWP tile?

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

$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 的代码中。

关于powershell - 如何使用 powershell 为 Windows 10 通用应用程序创建桌面快捷方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38359492/

相关文章:

.net - 如何在 PowerShell 中将 SID 转换为帐户名?

c# - 在 OneDrive 上创建文本文件以设置和获取数据

javascript - UWP BTLE : Cannot read device advertisements

powershell - 如何通过 "killed"或任务管理器在我的进程为 "stop-process"时运行 PowerShell 函数?

powershell - 使用 PowerShell 获取本地计算机和所有用户证书

使用 where-object 编写 Powershell 脚本

C# 通用应用程序 : automatically scroll to bottom of textbox after setting new text programmatically

c# - 如何为 UWP 应用创建 Headless Unittest 库

c# - 如何隐藏 Xamarin.Forms UWP 中的默认工具栏按钮(三个点)

powershell - 使用非字符串作为 $env : variable