Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I find out when my PC was last booted?

14 views
Skip to first unread message

Timo Salmi

unread,
Apr 13, 2006, 3:50:19 PM4/13/06
to
DRAFT: 136) How do I find out when my PC was last booted?

@echo off & setlocal enableextensions
for /f "tokens=3,4" %%c in (
'net statistics server^|find "Statistics since"') do (
set lastboot=%%c %%d
)
echo Last booted %lastboot%
endlocal & goto :EOF

The output might be e.g.
C:\_D\TEST>cmdfaq
Last booted 11.04.2006 09:17

All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Useful script files and tricks ftp://garbo.uwasa.fi/pc/link/tscmd.zip

John Dill

unread,
Apr 13, 2006, 3:58:57 PM4/13/06
to
My net statistics server command has this format:

Statistics since 4/13/2006 8:54 AM

A slight tweak in your for loop is all that's needed to handle my case.

Best,
John

zackrspv

unread,
Apr 13, 2006, 3:59:56 PM4/13/06
to
If i may ask, Prof Timo, why are you : & setlocal enableextensions
when you are not calling any expanded variable?

Phil Robyn

unread,
Apr 13, 2006, 5:51:08 PM4/13/06
to
Timo Salmi wrote:

> DRAFT: 136) How do I find out when my PC was last booted?
>
> @echo off & setlocal enableextensions
> for /f "tokens=3,4" %%c in (
> 'net statistics server^|find "Statistics since"') do (
> set lastboot=%%c %%d
> )
> echo Last booted %lastboot%
> endlocal & goto :EOF
>
> The output might be e.g.
> C:\_D\TEST>cmdfaq
> Last booted 11.04.2006 09:17
>
> All the best, Timo
>

c:\cmd>dir /ah \pagefile.sys | find "/"
04/11/2006 12:02 PM 2,145,386,496 pagefile.sys

--
Phil Robyn
University of California, Berkeley

Timo Salmi

unread,
Apr 13, 2006, 11:37:16 PM4/13/06
to
zackrspv wrote:
> If i may ask, Prof Timo, why are you : & setlocal
> enableextensions when you are not calling any expanded variable?

I am using a standard frame for my FAQ scripts the first and the last
lines being

@echo off & setlocal enableextensions

endlocal & goto :EOF

Although not always necessary this ensures that the extensions are
on by default

foxidrive

unread,
Apr 14, 2006, 1:58:46 AM4/14/06
to

You use a swap file? How quaint... ;-D

charles

unread,
Apr 14, 2006, 11:45:36 AM4/14/06
to
On Thu, 13 Apr 2006 22:50:19 +0300, Timo Salmi <t...@uwasa.fi> wrote:

> 'net statistics server^|find "Statistics since"') do (

or 'net statistics workstation' since the workstation service is more
likely to be running

Timo Salmi

unread,
Apr 14, 2006, 12:33:48 PM4/14/06
to

True. I actually already had changed it within my FAQ. But thank you.
I well might have missed it.

Dr John Stockton

unread,
Apr 14, 2006, 12:12:31 PM4/14/06
to
JRS: In article <443eab7f$0$7488$9b53...@news.fv.fi>, dated Thu, 13
Apr 2006 22:50:19 remote, seen in news:alt.msdos.batch.nt, Timo Salmi
<t...@uwasa.fi> posted :

>DRAFT: 136) How do I find out when my PC was last booted?

More generally, one can find out when a given batch file was last run by
examining the date/time of whatever.log, if one puts one of
REM > c:\whatever.log
touch c:\whatever.log
in the batch file. In at least some systems, REM generates a new zero-
length file.

Then one might use CMDFAQ #45 or BATFAQ #81 or NOWMINUS.

CMDFAQ #70, days in month, VBS - you could use, instead of the six-line
FOR loop,

DaysInMonth = Day(DateSerial(YYYY, MM+1, 0))

and, what's more, that will work outside Finland<g>. Well, yours may
often work outside Finland, but I'd not use it in places that prefer FFF
dates (and my VBS thinks it's in the USA). With yours, DaysInMonth
could be preset to an error message, for systems not Finn-compatible.

DaysInYear = 368 - Month(DateSerial(YYYY, 2, 29))

OrdinalDate = DateSerial(YYYY, MM, DD) - DateSerial(YYYY, 1, 0)

DayOfWeek = 1 + DateSerial(YYYY, MM, DD+5) mod 7 ' <g>


ISTM that any VBS code that builds a numeric date string and, implicitly
or explicitly, converts it into a CDate must be a candidate for
improvement with DateSerial. There's also TimeSerial.

regards,

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

Todd Vargo

unread,
Apr 14, 2006, 4:52:17 PM4/14/06
to

"Dr John Stockton" <j...@merlyn.demon.co.uk> wrote in message
news:A0O8xdFv...@merlyn.demon.co.uk...

> JRS: In article <443eab7f$0$7488$9b53...@news.fv.fi>, dated Thu, 13
> Apr 2006 22:50:19 remote, seen in news:alt.msdos.batch.nt, Timo Salmi
> <t...@uwasa.fi> posted :
>
> >DRAFT: 136) How do I find out when my PC was last booted?
>
> More generally, one can find out when a given batch file was last run

Unrelated to subject line. Let's stay focused.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

Todd Vargo

unread,
Apr 14, 2006, 4:52:17 PM4/14/06
to

"Timo Salmi" <t...@uwasa.fi> wrote in message
news:443fcef0$0$7477$9b53...@news.fv.fi...

> charles wrote:
> > On Thu, 13 Apr 2006 22:50:19 +0300, Timo Salmi <t...@uwasa.fi> wrote:
> >> 'net statistics server^|find "Statistics since"') do (
> > or 'net statistics workstation' since the workstation service is more
> > likely to be running
>
> True. I actually already had changed it within my FAQ. But thank you.
> I well might have missed it.

I occasionally need to boot without network connected.
Would that affect your result? (I'm not on network right now to test)

Timo Salmi

unread,
Apr 14, 2006, 10:42:32 PM4/14/06
to
Todd Vargo wrote:
> "Timo Salmi" <t...@uwasa.fi> wrote:

>> charles wrote:
>>> or 'net statistics workstation' since the workstation service
>>> is more likely to be running

>> True. I actually already had changed it within my FAQ. But thank
>> you. I well might have missed it.

> I occasionally need to boot without network connected. Would that
> affect your result? (I'm not on network right now to test)

Good point. I do not know. But intuitively the "workstation" version
feels more generic, so I'll be using that version unless something
new pops up.

Dr John Stockton

unread,
Apr 15, 2006, 8:32:02 AM4/15/06
to
JRS: In article <5YT%f.3600$mu2....@newssvr24.news.prodigy.net>, dated
Fri, 14 Apr 2006 20:52:17 remote, seen in news:alt.msdos.batch.nt, Todd
Vargo <tlv...@sbcglobal.netz> posted :

>
>"Dr John Stockton" <j...@merlyn.demon.co.uk> wrote in message
>news:A0O8xdFv...@merlyn.demon.co.uk...
>> JRS: In article <443eab7f$0$7488$9b53...@news.fv.fi>, dated Thu, 13
>> Apr 2006 22:50:19 remote, seen in news:alt.msdos.batch.nt, Timo Salmi
>> <t...@uwasa.fi> posted :
>>
>> >DRAFT: 136) How do I find out when my PC was last booted?
>>
>> More generally, one can find out when a given batch file was last run
>
>Unrelated to subject line. Let's stay focused.

A Batch file can be run automatically at boot time; and, in at least
some systems of interest within news alt.msdos.batch.*, it is usual or
necessary to so run AUTOEXEC.BAT.

The relationship with the Subject should not have needed to be
explained.

If the process of interest necessarily creates a new identifiable file,
then there's no need to create a zero-length one especially; but there's
still a connection with Batch since Batch can be where the file date-
stamp is subsequently read.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk DOS 3.3, 6.20; Win98. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <URL:http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.

Timo Salmi

unread,
Apr 15, 2006, 4:42:54 PM4/15/06
to
Dr John Stockton wrote:
> A Batch file can be run automatically at boot time

As it happens, I have the following script in the Startup folder,
which is directly pertinent to the question discussed:

@echo off & setlocal enableextensions

set target_=C:\_L\TIMO\logon.txt
::
color 0B
echo +-------------------------------+
echo : Logging the user's logon :
echo : A script by Prof. Timo Salmi :
echo : Last modified Mon 21-Nov-2005 :
echo +-------------------------------+
echo.
echo %date% %time%
echo Making an entry to %target_%
::
if not defined temp goto :EOF
set temp_=%temp%
if exist c:\_l\temp set temp_=C:\_L\TEMP
::
gawk 'BEGIN{printf"@set
wd_=%%s\n",strftime("%%a",systime())}'>%temp_%\weekday$.cmd
for %%c in (call del) do %%c %temp_%\weekday$.cmd
::
echo Logon: %COMPUTERNAME% %wd_% %date% %time%
%USERNAME%>%temp_%\logon1.tmp
if not exist %target_% (
copy /y %temp_%\logon1.tmp %target_% > nul
goto _out
)
copy %target_% %temp_%\logon2.tmp > nul
copy /y %temp_%\logon1.tmp + %temp_%\logon2.tmp %target_% > nul
::
:_out
for %%f in (logon1.tmp logon2.tmp weekday$.cmd) do if exist
%temp_%\%%f del %temp_%\%%f
endlocal & goto :EOF

Todd Vargo

unread,
Apr 15, 2006, 11:33:13 PM4/15/06
to

"Timo Salmi" <t...@uwasa.fi> wrote in message
news:44415ad5$0$26565$9b53...@news.fv.fi...

> Dr John Stockton wrote:
> > A Batch file can be run automatically at boot time
>
> As it happens, I have the following script in the Startup folder,
> which is directly pertinent to the question discussed:
>
> @echo off & setlocal enableextensions
> set target_=C:\_L\TIMO\logon.txt
> ::
> color 0B
> echo +-------------------------------+
> echo : Logging the user's logon :
> echo : A script by Prof. Timo Salmi :
> echo : Last modified Mon 21-Nov-2005 :
> echo +-------------------------------+
snip...

Then your subject line is deceiving. Instead of "How do I find out when my
PC was last booted?" it should now be 'How do I log when a user last logged
in?'.

BTW, do the words 'unnecessary bloat' mean anything? ;^)

Timo Salmi

unread,
Apr 16, 2006, 12:10:33 AM4/16/06
to
Todd Vargo wrote:
> "Timo Salmi" <t...@uwasa.fi> wrote in message
>> echo Logging the user's logon

> Then your subject line is deceiving. Instead of "How do I find out


> when my PC was last booted?" it should now be 'How do I log when a
> user last logged in?'.

> BTW, do the words 'unnecessary bloat' mean anything? ;^)

I'm ducking. "We know the drill".

Al Dunbar

unread,
Apr 16, 2006, 1:50:36 AM4/16/06
to

"Timo Salmi" <t...@uwasa.fi> wrote in message
news:443f18f0$0$26562$9b53...@news.fv.fi...

> zackrspv wrote:
> > If i may ask, Prof Timo, why are you : & setlocal
> > enableextensions when you are not calling any expanded variable?
>
> I am using a standard frame for my FAQ scripts the first and the last
> lines being
>
> @echo off & setlocal enableextensions
> endlocal & goto :EOF
>
> Although not always necessary this ensures that the extensions are
> on by default

Also, "setlocal" ensures that no environment variables are changed by the
script.

/Al


0 new messages