Commit 29864ba9 by yunpeng.song

增加全家vpn连接,启动时检查并停止所有vpn进程

parent d9cdb41c
......@@ -11,6 +11,7 @@ MainWindow::MainWindow(QWidget *parent) :
ui(new Ui::MainWindow)
{
ui->setupUi(this);
_killVpnexe();
//通过qprocess启动cmd
_exe.setProgram("cmd");
connect(&_exe,&QProcess::readyRead,this,&MainWindow::on_readStandardContent);
......@@ -43,7 +44,7 @@ void MainWindow::on_btn_connect_clicked()
_getVpnStatus();
if(!_vpnStatus)
{
QString file = qApp->applicationDirPath()+"/"+_setting->value("info/fileName").toString();
QString file = qApp->applicationDirPath()+"/"+_setting->value("info/MCDfileName").toString();
qDebug()<<file;
QByteArray command= QString("vpncli.exe -s <%1\n").arg(file).toLocal8Bit();
qDebug()<<command;
......@@ -67,6 +68,7 @@ void MainWindow::on_readStandardContent()
if(_isFirst)
ui->textEdit->clear();
QString content = QString::fromLocal8Bit(_exe.readAllStandardOutput());
qDebug()<<content;
content.replace("\n","\r");
QStringList list =content.split('\r');
foreach(QString str,list)
......@@ -101,8 +103,31 @@ void MainWindow::_getVpnStatus()
_exe.write("vpncli.exe state\n");
}
void MainWindow::_killVpnexe()
{
QProcess process;
process.execute("TASKKILL /IM vpncli.exe /F");
process.execute("TASKKILL /IM vpnui.exe /F");
process.close();
}
void MainWindow::on_btn_query_clicked()
{
_isFirst = true;
_getVpnStatus();
}
void MainWindow::on_pushButton_clicked()
{
_isFirst = true;
_getVpnStatus();
if(!_vpnStatus)
{
QString file = qApp->applicationDirPath()+"/"+_setting->value("info/QJfileName").toString();
qDebug()<<file;
QByteArray command= QString("vpncli.exe -s <%1\n").arg(file).toLocal8Bit();
qDebug()<<command;
//_exe.write("vpncli.exe -s < f:\\myfile.dat\n");
_exe.write(command);
}
}
......@@ -31,6 +31,8 @@ private slots:
//查询状态
void on_btn_query_clicked();
void on_pushButton_clicked();
private:
bool _isFirst;
SysTray m_tray;
......@@ -40,6 +42,7 @@ private:
bool _vpnStatus;
//获取vpn状态
void _getVpnStatus();
void _killVpnexe();
};
#endif // MAINWINDOW_H
......@@ -24,14 +24,14 @@
</rect>
</property>
<property name="text">
<string>启动vpn</string>
<string>启动麦当劳vpn</string>
</property>
</widget>
<widget class="QPushButton" name="btn_disconnect">
<property name="geometry">
<rect>
<x>30</x>
<y>120</y>
<y>240</y>
<width>111</width>
<height>41</height>
</rect>
......@@ -82,6 +82,19 @@
<string>查询状态</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>30</x>
<y>120</y>
<width>111</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>启动全家VPN</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment