启动本地QQ程序,需要在本地安装程序,有两种方式
一、安装本地协议服务(添加注册表)
1、创建文本文件,reg.txt输入以下命令
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\openQQTest]
"URL Protocol"="D:\\Program Files (x86)\\Tencent\\QQ\\Bin\\QQ.exe"
@="openQQTestProtocol"
[HKEY_CLASSES_ROOT\openQQTest\DefaultIcon]
@="D:\\Program Files (x86)\\Tencent\\QQ\\Bin\\QQ.exe,1"
[HKEY_CLASSES_ROOT\openQQTest\shell]
[HKEY_CLASSES_ROOT\openQQTest\shell\open]
[HKEY_CLASSES_ROOT\openQQTest\shell\open\command]
@="\"D:\\Program Files (x86)\\Tencent\\QQ\\Bin\\QQ.exe\" \"%1\""
2、把文件改成reg.reg,双击执行把上述内容添加到注册表
3、在html远程服务器页面内添加
<a href="openQQTest://">Open QQ</a>
访问这个页面,点击上述连接既可以提示是否打开QQ
二、第二种方式使用jsonp方式
在本地安装一个简易的http服务,端口假设为3000
页面中使用jquery访问
$.get("http://localhost:3000/",function(data){ console.log(data); });
我使用node.js写的本地服务
var app = require('express')();
//导入child_process模块的exec函数
var exec = require('child_process').exec;
app.get( '/', function ( req, res ) {
exec('a.bat', function(err, stdout, stderr ){ //第四行
//命令退出或者调用失败
if( err ){
//启动外部进程失败
console.log('child_process 退出,错误码是:',err.code);
return;
}
});
res.jsonp( { success: true } );
});
app.listen(3000);
可以看出,上述服务一旦被访问则,启动a.bat批处理命令
"D:\Program Files (x86)\Tencent\QQ\Bin\QQ.exe"
访问该页面时自动启动QQ