Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
Xboxer
- Posts: 25
- Joined: 27 Nov 2014 13:58
#1
Post
by Xboxer » 17 Dec 2014 03:17
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
Last edited by
Xboxer on 22 Dec 2014 10:52, edited 1 time in total.
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#2
Post
by foxidrive » 17 Dec 2014 03:50
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
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#3
Post
by Squashman » 17 Dec 2014 07:23
Code: Select all
H:\>systeminfo | find "System Boot Time:"
System Boot Time: 12/17/2014, 7:06:49 AM
-
Xboxer
- Posts: 25
- Joined: 27 Nov 2014 13:58
#4
Post
by Xboxer » 17 Dec 2014 23:08
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
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#5
Post
by foxidrive » 18 Dec 2014 00:18
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
-
Xboxer
- Posts: 25
- Joined: 27 Nov 2014 13:58
#6
Post
by Xboxer » 18 Dec 2014 17:38
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