批处理的小小应用

 

 

########################RUN.BAT######################

ECHO OFF

REM 判�噙M程

:run

tasklist | find /i "WinVNC.exe" >nul 2>nul && goto Report_S || goto Report_F

REM 定�r器

:TT

ping 127.0.0.1 -n 1800

goto run

REM 生成成功�蟾�

:Report_S

@echo =======================%date:~0,10% %time:~0,8%=======================>>%date:~0,4%-%date:~5,2%-%date:~8,2%.log

ping 192.168.1.22 -n 1 >nul 2>nul && echo 192.168.1.22 通 >>%date:~0,4%-%date:~5,2%-%date:~8,2%.log || echo 192.168.1.22 不通                                              X >>%date:~0,4%-%date:~5,2%-%date:~8,2%.log

@echo. >>%date:~0,4%-%date:~5,2%-%date:~8,2%.log

@echo WinVNC 正常!正在�\行��中! >>%date:~0,4%-%date:~5,2%-%date:~8,2%.log

@echo =================================================================>>%date:~0,4%-%date:~5,2%-%date:~8,2%.log

@echo. >>%date:~0,4%-%date:~5,2%-%date:~8,2%.log

@echo. >>%date:~0,4%-%date:~5,2%-%date:~8,2%.log

goto TT

REM 生成失��蟾�

:Report_F

@echo =======================%date:~0,10% %time:~0,8%=======================>>%date:~0,4%-%date:~5,2%-%date:~8,2%.log

ping 192.168.1.22 -n 1 >nul 2>nul && echo 192.168.1.22 通 >>%date:~0,4%-%date:~5,2%-%date:~8,2%.log || echo 192.168.1.22 不通                                              X >>%date:~0,4%-%date:~5,2%-%date:~8,2%.log

@echo. >>%date:~0,4%-%date:~5,2%-%date:~8,2%.log

@echo WinVNC ��常!未能正常�\行!                                     X>>%date:~0,4%-%date:~5,2%-%date:~8,2%.log

@echo =================================================================>>%date:~0,4%-%date:~5,2%-%date:~8,2%.log

@echo. >>%date:~0,4%-%date:~5,2%-%date:~8,2%.log

@echo. >>%date:~0,4%-%date:~5,2%-%date:~8,2%.log

goto Restart

REM 重新��映绦�

:Restart

@echo =======================%date:~0,10% %time:~0,8%=======================>>%date:~0,4%-%date:~5,2%-%date:~8,2%.log

@echo �L�重新��映绦颍� >>%date:~0,4%-%date:~5,2%-%date:~8,2%.log

Start C:\winsock\winvnc\WinVNC.exe

ping 127.0.0.1 -n 10

@echo. >>%date:~0,4%-%date:~5,2%-%date:~8,2%.log

tasklist | find /i "WinVNC.exe" >nul 2>nul && echo 程序已重新��樱� >>%date:~0,4%-%date:~5,2%-%date:~8,2%.log || echo 程序未能重新��樱���z查原因!!!                              X>>%date:~0,4%-%date:~5,2%-%date:~8,2%.log

@echo =================================================================>>%date:~0,4%-%date:~5,2%-%date:~8,2%.log

@echo. >>%date:~0,4%-%date:~5,2%-%date:~8,2%.log

@echo. >>%date:~0,4%-%date:~5,2%-%date:~8,2%.log

goto TT

########################RUN.BAT######################

以上为RUN.BAT的内容,有繁体字可以证明这是原创。呵呵。

上面这一大段代码只做了两件事,一是判断VNC进程是否正常并记录,如果不正常尝试重新启动并记录异常发生的时间,二是判断192.168.1.22是否是通的以判断网络是否有异常,VNC是远程连接的进程。

如果直接运行这个文件当然是可以的,我们都知道在Windows下运行BAT文件是有黑框的,所以接着送上下面这个。

#############RUN.VBS##############

 

Set ws=CreateObject("Wscript.Shell")

ws.run "Run.bat",vbhide

#############RUN.VBS##############

就两句代码,意思就是隐藏RUN.VBS。

 

 

 

 

 

你可能感兴趣的:(职场,bat,自动,批处理,休闲)