@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
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
> 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
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
You use a swap file? How quaint... ;-D
> '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.
>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.
Unrelated to subject line. Let's stay focused.
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
I occasionally need to boot without network connected.
Would that affect your result? (I'm not on network right now to test)
>> 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.
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.
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
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? ;^)
> 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".
Also, "setlocal" ensures that no environment variables are changed by the
script.
/Al