一,背景
Windows 软件安装到客户机器上,出现问题 需要对其进行远程支持,前期使用向日葵免费版,但是向日葵这个软件不可控,万一弹个广告或者哪天不能用了 都是承担不起的,所以基于frp 内网床头+vnc 局域网远程访问,实现一套自己可控的 远程支持系统
二,实现方案
(2),vnc 编译。
编辑很简单,下载源码,cmake生成vs文件,vs编译(https://www.tightvnc.com/download.php)
(3),Qt 业务逻辑编写
1.客户按下快捷键,或者点击远程支持,启动 单独的 exe ,并把 关键参数传递过去。
QString exeFile = QCoreApplication::applicationDirPath()+QString("/remotesupport.exe");
if(!QFile::exists(exeFile)){
return;
}
QString path = QCoreApplication::applicationDirPath()+QString("/remotesupport.exe --name %1").arg(SettingController::GetInst().getUser());
path.replace("/","//");
std::string exepath = path.toLocal8Bit().toStdString();
LOG(INFO)<<"remotehelp path.... "<<path;
WinExec(exepath.c_str(),SW_SHOWDEFAULT);
LOG(INFO)<<"remote help error.."<<GetLastError();
2.remotesupport.exe 主要功能如下
启动vnc
if(isExistProcess("tvnserver.exe")){
KillProcess("tvnserver.exe");
}
QString cmdParam =QCoreApplication::applicationDirPath()+"/vnc/tvnserver.exe";
QProcess process;
m_vncOk = process.startDetached(cmdParam,QStringList());
if(m_vncOk)
qDebug()<<"vnc start success!!!";
else
qDebug()<<"vnc start failed..."<<cmdParam<<m_vncOk<<process.errorString();
写frp配置文件
QString filepath = QCoreApplication::applicationDirPath()+"/frp/frpc.ini";
QFile file(filepath);
//方式:Append为追加,WriteOnly,ReadOnly
if (!file.open(QIODevice::WriteOnly|QIODevice::Text)) {
return;
}
QTextStream out(&file);
out.setCodec("utf-8");
out<<"[common]"<<endl;
out<<"server_addr="<<m_serverIp<<endl;
out<<"server_port="<<m_serverPort<<endl;
out<<"token = klxx!1234"<<endl;
out<<endl;
out<<"["<<m_name<<"]"<< endl;
out<<"type=tcp"<<endl;
out<<"local_ip="<<m_localIp<<endl;
out<<"local_port="<<m_localPort<<endl;
out<<"remote_port=0"<<endl;
out.flush();
file.close();
启动frp
if(isExistProcess("frpc.exe")){
KillProcess("frpc.exe");
}
QString cmdParam =QCoreApplication::applicationDirPath()+"/frp/frpc.exe";
QStringList list;
list<<"-c"<<QCoreApplication::applicationDirPath()+"/frp/frpc.ini";
QProcess process;
m_frpOk = process.startDetached(cmdParam,list);
if(m_frpOk)
qDebug()<<"frp start success!!!";
else
qDebug()<<"frp start failed..."<<cmdParam<<m_frpOk<<process.errorString();