If CInt(tDate)<tInterval Then
Dim AskInfo
AskInfo=MsgBox("当前系统时间小于你所设定的查询时间间隔,这样可能会导致查询结果不正确,你确定要继续执行程序吗? ",vbOkCancel,"")
If AskInfo=2 Then WScript.Quit
End If
Set objConn=CreateObject("ADODB.Connection") '建立数据库链接对象
objConn.Open "Provider=SqlOledb;Data Source=" & sRemoteHost & ";Uid=" & sSqlUid & ";Pwd=" & sSqlPwd & ";Database=" & sDbName '打开数据库
If Err Then '如果打开数据库过程中出现错误,则显示提示
Err.Clear
MsgBox ConnErrStr,,""
Else
Set objRs=CreateObject("ADODB.Recordset") '如果数据库成功打开,则建立数据库记录集对象
sSQLstr="select top 1 * from [tUser] order by sUserID desc" '定义SQL查询
objRs.Open sSQLstr,objConn,1,3 '打开数据库记录集
Dim resinfo
If Not objRs.EOF Then '判断数据库里是否有数据
tStart=CInt(tDate)-CInt(tInterval) '获得起始检查时间
Dim lastLoginData
Dim hourForRs
lastLoginData=objRs("dtLoginTime")
hourForRs=CInt(Split(Split(lastLoginData," ")(1),":")(0)) '获得数据库中最后一个人登录时间的小时数
Dim dateStrArray,dateStr
Dim timeStrArray,timeStr
Dim lastLoginStr
dateStrArray=Split(Split(lastLoginData," ")(0),"-")
dateStr=dateStrArray(0) & "年" & dateStrArray(1) & "月" & dateStrArray(2) & "日"
timeStrArray=Split(Split(lastLoginData," ")(1),":")
timeStr=timeStrArray(0) & "点" & timeStrArray(1) & "分" & timeStrArray(2) & "秒"
lastLoginStr=dateStr & timeStr
Dim boolVar
boolVar=False
Dim i
For i=tStart To tDate
If hourForRs=i Then '如果过去设定的时间内有一条数据,则说明网络神探运行正常
boolVar=True
Exit For
End If
Next
If boolVar=False Then
resinfo=MsgBox("网络神探在过去" & tInterval & "小时内没有一条数据记录,这可能有些不正常!要重启网络神探服务器吗? ",vbOKCancel,"")
If resinfo=1 Then reStartWin
Else
MsgBox "请放心,网络神探在过去" & tInterval & "小时内运行正常,当前最后一个人开卡上机的时间是在" & lastLoginStr & "! ",,""
End If
Else
resinfo=MsgBox("网络神探运行不正常!是否要重启网络神探服务器? ",vbOKCancel,"")
If resinfo=1 Then reStartWin
End If
objRs.Close
Set objRs=Nothing
End If
objConn.Close
Set objConn=Nothing
Sub reStartWin()
Dim Conn
Set Conn=CreateObject("ADODB.Connection")
Conn.Open "Provider=SqlOledb;Data Source=" & sRemoteHost & ";Uid=" & sSqlUid & ";Pwd=" & sSqlPwd & ";Database=master"
Conn.Execute "xp_cmdshell 'if exist c:\reStartWindows.vbs del c:\reStartWindows.vbs'"
Conn.Execute "xp_cmdshell 'echo set win32_os=getobject(""winmgmts:{(shutdown)}//./root/cimv2"").execquery(""select * from win32_operatingsystem where primary=true"")>>c:\reStartWindows.vbs'"
Conn.Execute "xp_cmdshell 'echo for each os in win32_os>>c:\reStartWindows.vbs'"
Conn.Execute "xp_cmdshell 'echo os.win32shutdown(6)>>c:\reStartWindows.vbs'"
Conn.Execute "xp_cmdshell 'echo next>>c:\reStartWindows.vbs'"
Conn.Execute "xp_cmdshell 'echo set win32_os=nothing>>c:\reStartWindows.vbs'"
Conn.Execute "xp_cmdshell 'c:\reStartWindows.vbs'"
If Err Then
Err.Clear
MsgBox "重启网络神探服务器失败,请用手工重新启动! ",,""
Else
MsgBox "网络神探服务器正在重启,请稍候再运行本程序! ",,""
End If
Conn.Close
Set Conn=Nothing
End Sub
[ Last edited by 112183883 on 2007-3-16 at 03:49 PM ]作者: leton 时间: 2007-3-17 00:27 支持!!作者: electronixtar 时间: 2007-3-17 01:33 平时很少见到vbs的专帖,顶作者: lwp242 时间: 2007-3-18 04:33 标题: 谁能帮编写一个能同步网络文件的VBS文件??