Skip navigation

JSI Tip 8487. How can a script retrieve the date/time that the local machine was re-started?


Using the net statistics Workstation command, I have scripted WhenStarted.bat to return the date and time that the local computer was started.

NOTE: The date and time that the Workstation service started is actually returned, but that should be close enough.

The syntax for using WhenStarted.bat is:

WhenStarted DateStarted TimeStarted

where DateStarted is a call directed environment variable that will contain the date that the Workstation service started, and TimeStarted is a call directed environment variable that will contain the time that the Workstation service started.

WhenStarted.bat contains:

@echo off
if \{%2\}==\{\} @echo Syntax WhenStarted Date Time&goto :EOF
for /f "Tokens=1-3*" %%a in ('net statistics Workstation^|Find "Statistics"') do (
 set %1=%%c
 set %2=%%d
)



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish