本帖最后由 tsys 于 2012-1-9 15:16 编辑
引用自A版的回复 http://www.autoitx.com/forum.php ... amp;page=1#pid90646,顺便将A版曾经发的代码贴出来:
问题是,如果将时间1 设置为:2330,时间2 设置为0830,那么一下代码在23:30分到早上8:00将只会运行 case else语句,请教如何解决。#NoTrayIcon
#AutoIt3Wrapper_Icon=e:\autoit3\Aut2Exe\Icons\GoLive.ico
#AutoIt3Wrapper_Compression=4
If Not FileExists(@ScriptDir & "\set.ini") Then
$sj = '时间1=0830' & @LF & '网关1=192.168.0.253' & @LF & '时间2=2030' & @LF & '网关2=192.168.0.1'
IniWriteSection(@ScriptDir & '\set.ini', '配置', $sj)
EndIf
$time1 = IniRead(@ScriptDir & "\set.ini", "配置", "时间1", "")
$time2 = IniRead(@ScriptDir & "\set.ini", "配置", "时间2", "")
$GateWay_1 = IniRead(@ScriptDir & "\set.ini", "配置", "网关1", "")
$GateWay_2 = IniRead(@ScriptDir & "\set.ini", "配置", "网关2", "")
If $time1 = "" Or $time2 = "" Or $GateWay_1 = "" Or $GateWay_2 = "" Then _;如果无法从INI文件中获取全部数据 就给出提示
Exit (MsgBox(0, "友情提示", "请先配置好 set.ini 文件 "))
If StringLen($time1 & $time2) <> 8 Then Exit (MsgBox(0, "友情提示", "时间格式不对,请使用4位数(且不带“:”) "))
Dim $WAY, $zx = 0
While 1
Switch @HOUR & @MIN
Case $time1 To $time2
If $WAY = 2 Or $zx = 0 Then
$WAY = 1
$zx = 1
GateWAY($GateWay_1)
EndIf
Case Else
If $WAY = 1 Or $zx = 0 Then
$WAY = 2
$zx = 1
GateWAY($GateWay_2)
EndIf
EndSwitch
Sleep(2000)
WEnd
Func GateWAY($GateWay)
Dim $array[1]
$array[0] = $GateWay
$strComputer = "."
$objWMIService = ObjGet("winmgmts:\" & $strComputer & "\root\cimv2")
$colNetAdapters = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
If IsObj($colNetAdapters) Then
For $objNetAdapter In $colNetAdapters
$objNetAdapter.SetGateways($array)
Next
EndIf
EndFunc ;==>GateWAY
|