【问题标题】:custom protocol handler via powershell script通过 powershell 脚本自定义协议处理程序
【发布时间】:2016-11-14 19:34:05
【问题描述】:

已回答问题.. 我已将此问题编辑为可行的解决方案。


这里是场景。 安装了 Jitsi VOIP 软件的 Windows 10 工作站。 我为 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,则显示消息“无法拨打此号​​码”

这是我为这个新的 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 注册条目几乎相同,但当我尝试运行 chk:1234567890 时,我收到错误 "Apllication not found" ,所以 打开命令有点不对劲......

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

以及 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,则显示无法拨打消息。

再次......我认为问题在于注册表项......特别是命令/打开部分......

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

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

【问题讨论】:

    标签: windows powershell registry


    【解决方案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"
    

    【讨论】:

    • 宾果游戏!就是这样。谢谢你 ! ! ! !
    猜你喜欢
    • 2013-04-28
    • 1970-01-01
    • 2011-10-28
    • 1970-01-01
    • 2011-01-30
    • 2011-09-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多