通过 powershell 脚本自定义协议处理程序

custom protocol handler via powershell script

问题已回答。我已将此问题编辑为有效解决方案。


这是场景。 Windows 10 个安装了 Jitsi VOIP 软件的工作站。 我为 SIP 创建了一个协议处理程序:使用此注册表项..

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\sip]
@="URL: SIP Protocol handler"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\sip\DefaultIcon]
@="C:\Program Files (x86)\Jitsi\sc-logo.ico"
[HKEY_CLASSES_ROOT\sip\shell]
[HKEY_CLASSES_ROOT\sip\shell\open]
[HKEY_CLASSES_ROOT\sip\shell\open\command]
@="\"C:\Program Files (x86)\Jitsi\Jitsi.exe\" %1"

这部分有效。输入 sip:1234567890 作为 运行 命令拨打号码。

我想做的是创建一个名为 CHK 的新协议:它向本地网络服务器发出 http 请求,如果网络服务器 响应 0,拨号码。如果响应为 1,则显示消息 "this number can't be dialed"

这是我为这个新的 chk 协议创建的注册表项

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\chk]
@="URL: CHK Protocol handler"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\chk\DefaultIcon]
@="C:\Program Files (x86)\Jitsi\sc-logo.ico"
[HKEY_CLASSES_ROOT\chk\shell]
[HKEY_CLASSES_ROOT\chk\shell\open]
[HKEY_CLASSES_ROOT\chk\shell\open\command]
@="\"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe\"
-File C:\DNC\dnc.ps1 %1"

尽管这与 SIP 注册条目几乎相同,但当我尝试 运行ning chk:1234567890 时,我得到一个错误 "Apllication not found",所以 open 命令有问题....

编辑:我是对的,是打开命令。我把引号放错地方了

和dnc.ps1脚本的内容...

$w=$args[0]

$chprot,$num = $w.split(':',2)

$url = "http://server/numchk.php?ph=$num"

$webclient = New-Object System.Net.WebClient

$webpage = $webclient.DownloadString($url)

if ($webpage -match "0"){ 

$launch = "C:\Program Files (x86)\Jitsi\Jitsi.exe"
$prot = 'sip:'
$arguments = $prot + $num
start-process $launch $arguments        

} Else {

$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup("CANT DIAL $num ",0,"",0x0)
}

如果我 运行 通过 运行 命令 powershell -noexit -File c:\DNC\dnc.ps1 chk:1234567890
脚本 我可以看到脚本在做正确的事情,如果响应为零则拨打号码,如果响应为 1 则显示无法拨打消息。

再次..我认为问题出在注册表项上...特别是 command/open 部分...

[HKEY_CLASSES_ROOT\chk\shell\open\command]
@="\"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File C:\DNC\dnc.ps1\" %1"

将参数传递给我缺少的参数的一些技巧:(

我认为您在错误的地方引用了引号,所以它不是在寻找 "powershell.exe",而是在寻找名为 "powershell.exe -File C:\DNC\dnc.ps1".

的文件

这个有用吗?

[HKEY_CLASSES_ROOT\chk\shell\open\command]
@="\"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe\" -File C:\DNC\dnc.ps1 %1"