本帖最后由 happy886rr 于 2016-3-28 20:29 编辑
回复 1# YYchen
在星线内插入你的批处理代码- @echo off
- setlocal enabledelayedexpansion
- for /f "tokens=1 delims=:" %%a in ('type "%~f0"^|findstr /n /c:"REM CPUPVBS"') do (set line=%%a)
- if not exist cpup.vbs (more +!line! "%~f0">cpup.vbs)
- start /min cpup.vbs
- REM 插入计时帧
- set t1=!time!
- ::*************************************************************
- REM 在星线内插入批处理代码
- REM 以下为演示代码,计算圆周率300位,引用CrLf优化算法
-
-
- set /a a=10000,c=300
- (set /a "a/=5,c=c/4*14-1"
- for /l %%a in (1 1 !c!) do set f[%%a]=!a!
- for /l %%i in (!c! -14 0) do (
- for /l %%j in (%%i -1 1) do (
- set /a d+=f[%%j]*%a%,f[%%j]=d%%(%%j*2+1^),d=d/(%%j*2+1^)*%%j
- )
- set /a c=a+d/%a%,a=d%%%a%+%a%,d=0
- set /p=!c:~-4!
- )
- )<nul
-
-
- ::*************************************************************
- REM 插入结束帧
- set t2=!time!
- set/a "t=(!t2:~0,2!-!t1:~0,2!)*3600+(1!t2:~3,2!-1!t1:~3,2!)*60+1!t2:~6,2!-1!t1:~6,2! ,t+=-86400*(t>>31),min=t/60"
- echo, &type log.txt &echo, &set /p =耗时!t!秒,约合!min!分钟 &exit
- REM CPUPVBS
- dim iCpuUsePercentage
- dim iSecond
- dim objFileStream
- dim objTextFileWriter
- dim objShell'Shell
- dim objFileInfo
- dim bIsExecuteBat
- iSecond=0
- bIsExecuteBat=False
- set objFileStream =CreateObject("Scripting.Filesystemobject")
- set objTextFileWriter=objFileStream.opentextfile("log.txt",8,True)
- While True
- Set objProc = GetObject("winmgmts:\\.\root\cimv2:win32_processor='cpu0'")
- iCpuUsePercentage=objProc.LoadPercentage
- objTextFileWriter.WriteLine("[" & Now & "] CPU使用率:" & iCpuUsePercentage & "%")
- if iCpuUsePercentage>=80 then
- iSecond=iSecond+1
- else
- iSecond=0
- bIsExecuteBat=False
- end if
- set objFileInfo=objFileStream.getfile("Log.txt")
- if (objFileInfo.size/1024/1024) >=2 then
- objTextFileWriter.close
- objFileStream.MoveFile "Log.txt",Replace(Replace(Replace(Now,":",""),"-","")," ","") & "BackLog.txt"
- set objTextFileWriter=objFileStream.opentextfile("log.txt",8,True)
- end if
- Wend
复制代码
|