服务器设置断网重连
使用校园网,隔天会断网,需要重连网,才能rdp。
-
批处理文件进行重新联网,将bat保存为ansi格式。
-
使用任务计划程序,勾选“不管用户是否登录都要运行”和“使用最高权限运行”,触发器设置系统启动时,延迟30s或者1min,启动程序,填写“起始于”路径,条件勾选“唤醒计算机运行此任务”,设置勾选“允许按需运行任务、”“如果过了计划开始时间,立即启动任务”和“如果任务运行时间超过以下时间,停止任务,3650天”。
@echo off if "%1" == "h" goto begin mshta vbscript:createobject("wscript.shell").run("""%~nx0"" h",0)(window.close)&&exit :Begin ping www.baidu.com if errorlevel 1 goto Reboot if errorlevel 0 goto Continue :Continue goto Begin: :Reboot taskkill /f /t /im "8021x.exe" start "" "C:\Program Files\Ruijie Networks\Ruijie Supplicant\RuijieSupplicant.exe" echo %date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2% 断网已重启,等待延时8秒...>>log.txt ::设置延时等待 ping -n 8 127.0.0.1 >nul goto Begin
以上为bat处理方法,另有Python方法,暂未尝试,也写在这里备忘。
# encoding: utf-8
import os
import time
def restart_Drc():
command = 'taskkill /F /IM DrClient.exe'
os.system(command)
command = 'taskkill /F /IM DrMain.exe'
os.system(command)
command = 'start '' C:\Drcom\DrUpdateClient\DrMain.exe'
os.system(command)
res = 0
while 1:
print('')
print('=======================正在检测网络重连=======================')
print('')
return1 = os.system('ping www.baidu.com')
if return1:
print('')
print('=======================网络异常,重启客户端=======================')
print('')
restart_Drc()
res += 1
else:
print('')
print('=======================网络正常=======================')
print('')
print('=======================已经重连%s次=======================' % res)
time.sleep(5)
参考链接:
https://www.cnblogs.com/hao-zhang/p/4052043.html
https://blog.csdn.net/weixin_38705903/article/details/104064834