我有一个我创建的 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()
Run Code Online (Sandbox Code Playgroud)
但是我正在为通用应用程序的目标使用什么而苦苦挣扎。
为 UWP 应用创建快捷方式与经典桌面不同。您可以参考我的另一个答案Wherelinked 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()
Run Code Online (Sandbox Code Playgroud)
您可以使用@TessellatingHeckler 提供的链接中的方法找到 AppUserModelId,并将Microsoft.SDKSamples.AdventureWorks.CS_8wekyb3d8bbwe!App
代码中的替换为您想要的 AppUserModelId。
小智 6
防止您的快捷方式具有标准资源管理器图标。$Shortcut.TargetPath
像这样改变:
$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()
Run Code Online (Sandbox Code Playgroud)
这样,快捷方式将与应用程序具有相同的图标。
您还可以*.url
通过 URI创建快捷方式(如果相关应用程序支持)(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()
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8943 次 |
最近记录: |