Uptime
The Uptime function returns the elapsed days, hours, minutes and seconds since the system booted.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:Uptime days hours mins [secs]
::
:: By: Ritchie Lawrence, 2003-09-24. Version 1.0
::
:: Func: Obtains the number of days, hours, minutes and seconds of uptime.
:: For NT4/2000/XP/2003.
::
:: Args: %1 var to receive number of days of uptime (by ref)
:: %2 var to receive number of hours of uptime (by ref)
:: %3 var to receive number of minutes of uptime (by ref)
:: %4 var to receive number of seconds of uptime (optional, by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal ENABLEEXTENSIONS & set "c=net statistics work"
set t=2&if "%date%z" LSS "A" set t=1
for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo/^|date') do (
for /f "tokens=%t%-4 delims=.-/ " %%d in ('date/t') do (
set %%a=%%d&set %%b=%%e&set %%c=%%f))
for /f "tokens=5-8 delims=:. " %%a in ('echo/^|time') do (
set "hh=%%a" & set "nn=%%b" & set "ss=%%c")
if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
set /a dd=100%dd%%%100,mm=100%mm%%%100
set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2
set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633
if 1%hh% LSS 20 set hh=0%hh%
set /a hh=100%hh%%%100,nn=100%nn%%%100,f=j*1440+hh*60+nn
for /f "tokens=3-8 delims=/:M " %%a in ('%c%^|findstr/b /c:"Stat"') do (
set mm=%%a&set dd=%%b&set yy=%%c&set hh=%%d&set nn=%%e%%f)
if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
set /a dd=100%dd%%%100,mm=100%mm%%%100
set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2
set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633
if 1%hh% LSS 20 set hh=0%hh%
if {%nn:~2,1%} EQU {P} if "%hh%" NEQ "12" set hh=1%hh%&set/a hh-=88
if {%nn:~2,1%} EQU {A} if "%hh%" EQU "12" set hh=00
if {%nn:~2,1%} GEQ {A} set nn=%nn:~0,2%
set /a hh=100%hh%%%100,nn=100%nn%%%100,s=j*1440+hh*60+nn,n=f-s
set /a d=n/1440,n%%=1440,h=n/60,n%%=60
endlocal & set "%1=%d%" & set "%2=%h%" & set "%3=%n%" ^
& (if "%4" NEQ "" set "%4=%ss%") & goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Parameters
%1 var to receive number of days of uptime (by ref)
%2 var to receive number of hours of uptime (by ref)
%3 var to receive number of minutes of uptime (by ref)
%4 var to receive number of seconds of uptime (optional, by ref)
Return Values
See parameters above.
Example
@echo off & setlocal ENABLEEXTENSIONS
call :Uptime d h n s
echo/Uptime is: %d% days, %h% hours, %n% minutes, %s% seconds.
goto :EOF
Remarks
The uptime reported by this function is typically less than +/- 30 seconds of the uptime reported by third party utilities such as SrvInfo from the Resource Kit and PsInfo from sysinternals.
山外有山,人外有人;低调做人,努力做事。
进入网盘(各种工具)~~
空间~~
cmd学习