Board logo

标题: [日期时间] 批处理如何求得win7的开机时长? [打印本页]

作者: tempasdf    时间: 2023-11-2 21:14     标题: 批处理如何求得win7的开机时长?

各位:
    在win7中,systeminfo中包含开机时间,如何通过cmd命令判断出本次开机时长大于2天以上?
作者: Five66    时间: 2023-11-2 22:22

非得要用systeminfo中包含开机时间和cmd命令不?
还有楼主你不是发过一个差不多的帖子?
作者: ShowCode    时间: 2023-11-3 10:27

回复 1# tempasdf


http://bbs.bathome.net/thread-66666-1-1.html#pid274306
这个代码保存为 1.bat 在我的Win7里面测试正常
作者: ShowCode    时间: 2023-11-3 10:42

回复 1# tempasdf


Win7-v2.bat
  1. @echo off
  2. for /f "tokens=2 delims=.=" %%a in ('wmic Path Win32_OperatingSystem get LastBootUpTime /value') do (
  3.     set "BootTime=%%a"
  4. )
  5. set "BootTime=%BootTime:~0,4%-%BootTime:~4,2%-%BootTime:~6,2% %BootTime:~8,2%:%BootTime:~10,2%:%BootTime:~12,2%"
  6. for /f "tokens=2 delims=: " %%a in ('powershell "(Get-Date) - (Get-Date '%BootTime%')" ^|findstr /b "Days"') do (
  7.     echo %%a
  8.     if %%a geq 2 (
  9.         echo 大于等于2天
  10.     ) else (
  11.         echo 小于2天
  12.     )
  13. )
  14. pause
复制代码

作者: ShowCode    时间: 2023-11-3 11:00

回复 1# tempasdf


Win7-v3.bat
  1. @echo off
  2. for /f "tokens=2,3 delims=, " %%a in ('systeminfo ^| findstr /i /b "系统启动时间"') do (
  3.     set "BootTime=%%a %%b"
  4. )
  5. for /f "tokens=2 delims=: " %%a in ('powershell "(Get-Date) - (Get-Date '%BootTime%')" ^|findstr /b "Days"') do (
  6.     echo %BootTime%
  7.     echo %%a
  8.     if %%a geq 2 (
  9.         echo 大于等于2天
  10.     ) else (
  11.         echo 小于2天
  12.     )
  13. )
  14. pause
复制代码





欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2