本帖最后由 chenronting 于 2011-9-5 17:16 编辑
RT:
在这里附上我的源码,希望大家看看那里出现问题了?还是说这样子的嵌套是不允许的?
#include <Constants.au3>
#RequireAdmin
Global $IniFile=@DesktopCommonDir & '\abc.ini'
Global $server=IniRead($IniFile,'Config','ServerIp','172.23.10.2')
If Not _jiancejihua() Then;检测是否加入任务计划
_jiarujihua();加入任务计划
EndIf
Local $fuwuduan=_jiancefuwuduan();检测服务器端
$Time=TimerInit()
;MsgBox(0,'服务端',$fuwuduan)
While Not $fuwuduan
Sleep (1000)
$fuwuduan=_jiancefuwuduan();检测服务端
If TimerDiff($Time) > 60000 Then _tuichudingyi(1);退出标志
WEnd
Local $biaozhiwei=_xierubiaozhiwei();写入标志位
Local $Time=TimerInit()
;MsgBox(0,'标志位',$biaozhiwei)
While Not $biaozhiwei
Sleep (1000)
$biaozhiwei=_xierubiaozhiwei();写入标志位
If TimerDiff($Time) > 60000 Then _tuichudingyi(2);退出标志
WEnd
_tuichudingyi(0)
Func _jiancejihua();检测计划
Local $foo = Run(@ComSpec & " /c " & 'schtasks ', "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
ProcessWaitClose($foo)
Local $text=StdoutRead($foo)
If StringInStr($text,"结束进程服务器") Then
Return 1
Else
Return 0
EndIf
EndFunc
Func _jiarujihua();添加计划
Run(@ComSpec & " /k " & 'schtasks /create /tn "结束进程服务器" /tr ' & @ScriptFullPath & ' /sc daily /st 03:00:00 ', "", @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD)
Return 1
EndFunc
Func _xierubiaozhiwei();写入标志位
If @IPAddress1 <> '0.0.0.0' And @IPAddress1 <> ' ' And @IPAddress1 <> '' Then
$IP=@IPAddress1
Else
$IP=@IPAddress2
EndIf
Return IniWrite($IniFile,'Client',$IP,1)
EndFunc
Func _jiancefuwuduan();检测服务端
Local $data=StringFormat('%2d年%2d月%2d日%2d时',@YEAR ,@MON,@MDAY,@HOUR)
$data=StringReplace($data,' ','0')
Return IniRead($IniFile,'server',$data,0);返回服务器是否已写入标志位
EndFunc
Func _jieshurenwu();结束进程
Local $ProcessList=IniReadSection(@ScriptDir & '\ProcessList','Process')
If Not @error Then
For $i =1 To $ProcessList[0][0]
ProcessClose($ProcessList[$i][0])
Next
Else
_tuichudingyi(3)
EndIf
EndFunc
Func _dengdaifuwuqi()
Local $Time=TimerInit()
While Not Ping($server)
Sleep(500)
If TimerDiff($Time) > 300000 Then _tuichudingyi(1);超时
WEnd
_qidongjincheng() Then;启动进程
EndFunc
Func _qidongjincheng()
Local $ProcessList=IniReadSection(@ScriptDir & '\ProcessList','Process')
If Not @error Then
For $i =1 To $ProcessList[0][0]
ShellExecute($ProcessList[$i][1]);启动程序
Sleep(300)
Next
Else
_tuichudingyi(3)
EndIf
EndFunc
Func _tuichudingyi($Flog=0)
Local $data=StringFormat('%2d年%2d月%2d日%2d时',@YEAR ,@MON,@MDAY,@HOUR)
$data=StringReplace($data,' ','0')
Switch $Flog
Case 0
FileWrite(@ScriptDir & '\log.log',$data & ':正常。' & @CRLF)
_jieshurenwu();结束进程
_dengdaifuwuqi();等待服务器
Exit
Case 1
FileWrite(@ScriptDir & '\log.log',$data & ':超时退出。' & @CRLF)
Exit
Case 2
FileWrite(@ScriptDir & '\log.log',$data & ':标志位无法写入。' & @CRLF)
Exit
Case 3
FileWrite(@ScriptDir & '\log.log',$data & ':其它异常错误!。' & @CRLF)
Exit
EndSwitch
EndFunc
|