连接网络bat

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
@echo off
title=NetKeeper-WiFi
::
::设置参数
::
SET netkeeper="D:\Program Files\NetKeeper\NetKeeper.exe"
SET nkTask="NK.exe"
SET wifi="D:\Program Files (x86)\kingsoft\kwifi\kwifi.exe"
SET wifiTask="kwifi.exe"

:: 获取管理员身份
echo Obtaining administrator identity ...
cd /d %~dp0
%1 start "" mshta vbscript:createobject("shell.application").shellexecute("""%~0""","::",,"runas",1)(window.close)&exit

:: 判断网络是否连接
echo;
echo Start network connection test ...
echo; >> ping.log
echo; >> ping.log
echo;
echo *********************%date% %time%********************* >> ping.log
::baidu DNS
ping /n 2 180.76.76.76>>ping.log
ping /n 2 180.76.76.76>tmp.log
echo; >> ping.log
for /f %%i in ('findstr /n "超时" tmp.log') do (set r=%%i)
del tmp.log

:: 判断是否连接网络
if defined r (
echo Start the network connection ...

::关闭wifi进程
echo close the wifi task ...
taskkill /f /t /im %wifiTask%

:: 启动netkeeper
echo;
echo start NetKeeper ...
start "" %netkeeper%

:: 等待连接
echo;
echo Waiting for the program to complete ...
echo please wait 30 seconds ...
timeout /t 30

:: 关闭NK进程
echo;
echo close the task ...
taskkill /f /t /im %nkTask%

:: 启动wifi
echo;
echo start kwifi ...
start "" %wifi%

:: 执行完成 关闭窗口
echo;
echo execution completed ...
echo Off automatically after 5 seconds ...
timeout /t 5

) else (

taskkill /f /t /im %nkTask%

echo;
echo Network connected ...
echo;
echo Off automatically after 5 seconds ...
echo;
timeout /t 10

)