Page 1 of 1
(SOLVED)-Help with DateTime Machine Restart batch
Posted: 17 Dec 2014 03:17
by Xboxer
Trying to retrieve the Date and Time when local machine was re-started from the Statistics command (net statistics Workstation)
Here is what I have so far, but it only gives out my current time.
Thanks for the help. xbox
ps: also found this batch here which looks promising but not working as well.
http://windowsitpro.com/windows/jsi-tip ... re-startedCode: Select all
@echo off
For /F "Tokens=2 Delims=: " %%A In ('net statistics workstation^| Findstr "^....Statistics"') Do Set "dATEtIME=%%A"
echo %dATEtIME%
pause
Re: Help with DateTime Machine Restart batch
Posted: 17 Dec 2014 03:50
by foxidrive
This works in Win 8.1 pro
Code: Select all
@echo off
For /F "Tokens=2* " %%A In ('net statistics workstation^| Findstr /i "Statistics" ') Do Set "dATEtIME=%%B"
echo %dATEtIME%
pause
If it fails for you then we need the screen output from
net statistics workstation
Re: Help with DateTime Machine Restart batch
Posted: 17 Dec 2014 07:23
by Squashman
Code: Select all
H:\>systeminfo | find "System Boot Time:"
System Boot Time: 12/17/2014, 7:06:49 AM
Re: Help with DateTime Machine Restart batch
Posted: 17 Dec 2014 23:08
by Xboxer
Thanks for the help and quick response guys! Both solutions work with either Windows 7 or 8.1, this is one of the better forums on the net as far as being responsive and giving correct solutions, way to go guys..
P.S. Foxidrive just so I can better understand how come your solution worked could you break down your batch and explain it.
Thanks, xbox
Re: Help with DateTime Machine Restart batch
Posted: 18 Dec 2014 00:18
by foxidrive
Xboxer wrote:P.S. Foxidrive just so I can better understand how come your solution worked could you break down your batch and explain it.
It takes every line with "Statistics" in it and then splits the tokens into the second word on the line (which is saved in %%A)
and the rest of the line (which is saved in %%B), and then sets the variable to %%B
"tokens=2*" controls how the line is split up as above, and * means the rest of the line.
When delims= is not included then the delimiters are set by default to spaces and TABs
Re: Help with DateTime Machine Restart batch
Posted: 18 Dec 2014 17:38
by Xboxer
Thanks for taking the time and explaining things Foxidrive! also discovered by using part of your script with the net user command that I can do the same.
xbox
Code: Select all
@Echo Off
SetLocal
For /F "Tokens=2* " %%A In ('Net User %UserName%^|Findstr /B /C:"Last logon"') Do Set "LastLogon=%%B"
Echo. %LastLogon%
Pause>Nul