本帖最后由 再世情緣 于 2013-12-10 07:26 编辑
- @echo off &color 0a &setlocal enabledelayedexpansion
- title 资源监视
- Rem 格式化date
- for /f "tokens=1,2" %%a in ("%date%") do (echo.%%a | findstr "星期" >nul &&set "date=!date: *=!" ||set "date=!date: 星期*=!")
- pushd "%cd%"
- rem 设置变量 Tm=循环时间,ds=创建监视进程偏移行数,tsk=任务偏移行数,谨慎修改!!!!!
- set /a "Tm=300","ds=27","tsk=35"
- :main
- rem 生成资源文件
- sures sures >sures.txt
- if not exist sures.txt (msg %username% /time:5 "错误!!未找到 sures.txt 文件!!!" &call exit)
- for /f "tokens=1,2,3 delims==" %%a in ('more "%~f0" +%tsk%') do (
- set /a "i=0","j=0"
- set "name=%%a" &set "tk1=%%b" &set "tk2=%%c"
- if not exist "%computername%_!name!.txt" (echo.日期 时间 机器名 !name!使用数量^/!name!空余数量)>"%computername%_!name!.txt"
- for /f "delims=" %%1 in ('findstr /i /c:"!tk1!" "sures.txt" 2^>nul') do (set /a "i+=1")
- for /f "delims=" %%1 in ('findstr /i /c:"!tk2!" "sures.txt" 2^>nul') do (set /a "j+=1")
- (echo.!date! !time! %computername% !i!^/!j!)>>"%computername%_!name!.txt"
- Rem 创建监视进程命令
- if not exist "!name!.bat" ((more "%~f0" +!ds!)>"!name!.bat" )
- Rem 运行监视进程命令
- (tasklist /v | findstr /I "cmd.exe") | findstr /i "!name!" >nul || start "" "!name!.bat"
- )
- ping localhost -n %Tm% >nul
- cls &goto :main
-
- Rem 监视进程命令
- @echo off &color 0a
- title %~n0
- :ds
- type "%computername%_%~n0.txt"
- ping localhost -n 30 >nul
- cls &goto :ds
-
- Rem Tsk 任务
- Agent=_12 RES IN USE=_12 RES AVAILABLE
- Telephony=INLINE.*_8 RES IN USE=INLINE.*_8 RES AVAILABLE
- Ntdll=_15 RES IN USE=_15 RES AVAILABLE
- Datebase=_4 RES IN USE=_4 RES AVAILABLE
- Soap=_50 RES IN USE=_50 RES AVAILABLE
复制代码 优化之后的代码,运行之后,会生成5个对应的监视窗口,监视窗口30秒更新窗口,
关于格式化date,本人是win7 64位,%date% 格式是 yyyy/mm/dd 没有星期。。。。所以,无法验证,但是,理论上应该不会出错。。。 |