![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-03 19:25 |
48,038 topics / 350,123 posts / today 0 new / 48,251 members |
| DOS批处理 & 脚本技术(批处理室) » [Original] Net Detective Running Status Checker |
| Printable Version 1,074 / 3 |
| Floor1 112183883 | Posted 2007-03-16 14:39 |
| 初级用户 Posts 31 Credits 128 | |
|
Dedicated to friends working in internet cafés: save the following code as any VBS file, and double-click it to run.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '//ProgramName: Net Detective Runtime Status Viewer '//Author: Eleven Wolf '//About: Friends who work in internet cafés all know this thing called Net Detective. I won't say what it's used for. The annoying thing is that it often has problems, so every once in a while you still have to open the webpage and check whether it is running normally. Otherwise, the Ministry of Public Security may end up CALLing you. '//...... Since it's the same repeated action every time, I thought of writing a small program to replace manual checking, and that's how this thing came about. In the program you can customize how many hours of data to check for normal status. I preset it to two hours, and you can also change it to whatever time you think '//...... is appropriate. If the Net Detective server becomes abnormal, you can also restart the server according to the program prompts. '//...... This is only a simplified version. In the full version, it can completely get rid of manual clicking and let the program query the server automatically at the loop interval you set. If the server becomes abnormal, it will automatically restart the server. The full version is almost finished now. If any friends need '//...... it, please leave a message and let me know. '//QQ: 112183883 '//EMail: 112183883@163.com '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Option Explicit On Error Resume Next 'Define some variables that will be used Dim sRemoteHost Dim sSqlUid Dim sSqlPwd Dim sDbName Dim tStart Dim tDate Dim tInterval Dim ConnErrStr sRemoteHost = "192.168.0.254" 'This is the IP address of the host where Net Detective is located in your internet café; please set it according to your own situation sSqlUid = "sa" 'SQL database username, no need to modify sSqlPwd = "rainsoft" 'SQL database password, no need to modify sDbName = "NetDetective" 'SQL database name, no need to modify tDate = Hour(Time()) 'Current time tInterval = 2 'Check time span, in hours. If you want to check the running status for the past 3 hours, set it to 3 ConnErrStr = "Net Detective connection failed. Possible reasons are as follows:" & vbcrlf & vbcrlf ConnErrStr = ConnErrStr & "1.Server IP address is incorrect;" & vbcrlf ConnErrStr = ConnErrStr & "2.Database username or password is incorrect;" & vbcrlf ConnErrStr = ConnErrStr & "3.The server has been shut down;" & vbcrlf 'Define the prompt message shown when Net Detective connection fails Dim objConn Dim objRs Dim sSQLstr If CInt(tDate)<tInterval Then Dim AskInfo AskInfo=MsgBox("The current system time is less than the query interval you set. This may cause incorrect query results. Are you sure you want to continue running the program? ",vbOkCancel,"") If AskInfo=2 Then WScript.Quit End If Set objConn=CreateObject("ADODB.Connection") 'Create a database connection object objConn.Open "Provider=SqlOledb;Data Source=" & sRemoteHost & ";Uid=" & sSqlUid & ";Pwd=" & sSqlPwd & ";Database=" & sDbName 'Open the database If Err Then 'If an error occurs while opening the database, display a prompt Err.Clear MsgBox ConnErrStr,,"" Else Set objRs=CreateObject("ADODB.Recordset") 'If the database opens successfully, create a database recordset object sSQLstr="select top 1 * from order by sUserID desc" 'Define SQL query objRs.Open sSQLstr,objConn,1,3 'Open the database recordset Dim resinfo If Not objRs.EOF Then 'Check whether there is data in the database tStart=CInt(tDate)-CInt(tInterval) 'Get the starting check time Dim lastLoginData Dim hourForRs lastLoginData=objRs("dtLoginTime") hourForRs=CInt(Split(Split(lastLoginData," ")(1),":")(0)) 'Get the hour of the last person's login time in the database Dim dateStrArray,dateStr Dim timeStrArray,timeStr Dim lastLoginStr dateStrArray=Split(Split(lastLoginData," ")(0),"-") dateStr=dateStrArray(0) & " year " & dateStrArray(1) & " month " & dateStrArray(2) & " day" timeStrArray=Split(Split(lastLoginData," ")(1),":") timeStr=timeStrArray(0) & " hour " & timeStrArray(1) & " minute " & timeStrArray(2) & " second" lastLoginStr=dateStr & timeStr Dim boolVar boolVar=False Dim i For i=tStart To tDate If hourForRs=i Then 'If there is one record within the set time period, then Net Detective is running normally boolVar=True Exit For End If Next If boolVar=False Then resinfo=MsgBox("Net Detective has had no data records in the past " & tInterval & " hours. This may be somewhat abnormal! Do you want to restart the Net Detective server? ",vbOKCancel,"") If resinfo=1 Then reStartWin Else MsgBox "Rest assured, Net Detective has been running normally in the past " & tInterval & " hours. The current latest time someone activated a card and went online was " & lastLoginStr & "! ",,"" End If Else resinfo=MsgBox("Net Detective is not running normally! Do you want to restart the Net Detective server? ",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 "Failed to restart the Net Detective server. Please restart it manually! ",,"" Else MsgBox "The Net Detective server is restarting. Please wait a moment before running this program again! ",,"" End If Conn.Close Set Conn=Nothing End Sub [ Last edited by 112183883 on 2007-3-16 at 03:49 PM ] |
|
| Floor2 leton | Posted 2007-03-17 00:27 |
| 初级用户 Posts 72 Credits 170 | |
|
Support
|
|
| Floor3 electronixtar | Posted 2007-03-17 01:33 |
| 铂金会员 Posts 2,672 Credits 7,493 | |
|
Usually you rarely see dedicated VBS threads, bump
|
|
| Floor4 lwp242 | Posted 2007-03-18 04:33 |
| 新手上路 Posts 2 Credits 6 | |
|
Can anyone help write a VBS file that can synchronize network files?? I want to synchronize one file from this server of mine to all the machines. How can this be done with a VBS script? Synchronize it at startup.
|
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |