Walter Mitty's helpful answer shows a PowerShell command that opens all shortcut files (*.lnk
) in the current folder, using Start-Process
.
Here is code that incorporates it into a shortcut-menu command definition named Open Shortcuts
, which will become available:
If shortcut files are present in a given folder, they are all opened (asynchronously), as if they had been double-clicked; in the absence of shortcuts, a warning is displayed.
Note that I'm targeting HKEY_CURRENT_USER\Software\Classes
rather than HKEY_CLASSES_ROOT
, which makes the definition user-specific and also doesn't require running with elevation:
# 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
}