我想获取Windows资源管理器上下文菜单权限(动词)及其背后的命令列表。像这样:
Open with notepad++ | C:\Program Files\NOtepad++\NppShell_06.dll
Add to archive | C:\Program Files\WinRAR\rarext.dll
Play with VLC | "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe"
--started-from-file --no-playlist-enqueue "%1"
等等。
我写了PS脚本来从上下文菜单中获取所有命令(我可以通过C#完成所有命令):
$ErrorActionPreference= 'silentlycontinue'
Set-Location -LiteralPath HKLM:\SOFTWARE\Classes\*\shellex\ContextMenuHandlers;
$o = Get-ChildItem -LiteralPath HKLM:\SOFTWARE\Classes\*\shellex\ContextMenuHandlers;
foreach($obj in $o)
{
$prop = (Get-ItemProperty $obj.PSChildName).'(default)';
"-------------------------------------------------------------";
try
{
$obj.PSChildName;
$sub = (Get-Item -LiteralPath ("HKLM:\SOFTWARE\Classes\CLSID\" + $prop.ToString())).GetSubKeyNames();
foreach($s in $sub)
{
(Get-ItemProperty -LiteralPath ("HKLM:\SOFTWARE\Classes\CLSID\" + $prop.ToString() + "\" + $s)).'(default)';
}
}
catch
{}
}
输出:
-------------------------------------------------------------
ANotepad++64
C:\Program Files\Notepad++\NppShell_06.dll
-------------------------------------------------------------
EPP
C:\Program Files\Windows Defender\shellext.dll
10.0.14393.1198
-------------------------------------------------------------
Open With
C:\Windows\system32\shell32.dll
-------------------------------------------------------------
WinRAR
C:\Program Files\WinRAR\rarext.dll
........
有脚本可以获取特定文件的动词:
$o = new-object -com Shell.Application
$folder = $o.NameSpace("C:\Users\User\Documents")
$file=$folder.ParseName("file.txt")
$file.Verbs() | select *
输出:
申请人姓名
&Open
&Print
&Edit
Edit with &Notepad++
Check with Windows Defender...
&Add to archive...
Add &to "file.rar"
Compress and email...
Compress to "file.rar" and email
.....
所以,我不知道如何结合这些解决方案。是否有一些命令/优雅的方式来做我想做的事情?