Walter Mitty 的有用答案*.lnk
显示了一个 PowerShell 命令,该命令打开当前文件夹中的所有快捷方式文件 ( ),使用Start-Process
.
这是将其合并到名为 的快捷菜单命令定义中的代码,该定义Open Shortcuts
将变为可用:
如果给定文件夹中存在快捷方式文件,则它们都被打开(异步),就像它们被双击一样;如果没有快捷方式,则会显示警告。
请注意,我的目标是HKEY_CURRENT_USER\Software\Classes
而不是HKEY_CLASSES_ROOT
,这使得定义是特定于用户的,并且也不需要使用海拔运行:
# Define a shortcut-menu command that opens all shortcut files (*.lnk) in the target folder (%V):
# Define the name to appear in the shortcut menu.
$commandName = 'Open Shortcuts'
# Define the PowerShell command to run, hidden, via mshta.exe, so that no PowerShell console window opens (temporarily).
$command = @"
mshta.exe vbscript:(CreateObject("WScript.Shell").Run("powershell.exe -noexit -noprofile -c `$f = Get-Item \""%V\*.lnk\""; if (`$f) { `$f | ForEach-Object { Start-Process `$_.FullName } } else { (New-Object -ComObject WScript.Shell).Popup(\""%V contains no shortcut files (*.lnk).\"",0,\""$commandName\"",48) }",0))(Window.Close)'
"@
# Define the shortcut-menu commands in the registry, for:
# * folders
# * the background of open folders (to apply the command to the open folder)
'Folder', 'Directory\Background' | ForEach-Object {
New-Item -Force "HKCU:\Software\Classes\$_\shell\$commandName\command" |
Set-ItemProperty -Name '(Default)' -Value $command
}