Advertisement
TechManDylan

uptime2

Nov 4th, 2024
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. @echo off
  2.  
  3. :: Set the window size
  4. mode con: cols=55 lines=10
  5.  
  6. :loop
  7. cls
  8. echo Saved uptime stats
  9. echo.
  10.  
  11. :: Get the current date, time, and uptime and save it to the file
  12. echo %date% %time% >> uptime.txt
  13. net statistics workstation | find "Statistics since" >> uptime.txt
  14. echo. >> uptime.txt
  15.  
  16. :: Extract the start date and time of uptime
  17. for /f "tokens=3-8" %%a in ('net statistics workstation ^| find "Statistics since"') do (
  18. set start_date=%%a
  19. set start_time=%%b %%c %%d
  20. )
  21.  
  22. :: Calculate the elapsed time in minutes
  23. for /f "tokens=1-4 delims=/: " %%a in ("%start_date% %start_time%") do (
  24. set /a start_year=%%a, start_month=%%b, start_day=%%c
  25. set /a start_hour=%%d, start_minute=%%e
  26. )
  27.  
  28. :: Get current date and time
  29. set /a current_year=%date:~6,4%
  30. set /a current_month=%date:~0,2%
  31. set /a current_day=%date:~3,2%
  32. set /a current_hour=%time:~0,2%
  33. set /a current_minute=%time:~3,2%
  34.  
  35. :: Calculate elapsed hours and minutes (approximated)
  36. set /a elapsed_minutes=(current_hour*60 + current_minute) - (start_hour*60 + start_minute)
  37. set /a elapsed_hours=elapsed_minutes / 60
  38. set /a elapsed_minutes=elapsed_minutes %% 60
  39.  
  40. :: Display the calculated uptime
  41. echo Current Uptime: %start_date% %start_time%
  42. echo Uptime (calculated): %elapsed_hours% hours and %elapsed_minutes% minutes
  43.  
  44. :: Wait for 5 minutes (300 seconds)
  45. timeout /t 300 /nobreak > nul
  46. goto loop
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement