C:\_G\WWW\~ELISANET\INFO\tscmd078.html
<http://www.elisanet.fi/tsalmi/info/tscmd078.html>
Copyright © 2003- by Prof. Timo Salmi  
Last modified Sun 28-Oct-2018 18:28:50

 
Assorted NT/2000/XP/.. CMD.EXE Script Tricks
From the html version of the tscmd.zip 1cmdfaq.txt file
To the Description and the Index
 

This page is edited from the 1cmdfaq.txt faq-file contained in my tscmd.zip command line interface (CLI) collection. That zipped file has much additional material, including a number of detached .cmd script files. It is recommended that you also get the zipped version as a companion.

Please see "The Description and the Index page" for the conditions of usage and other such information.



78} Is it possible automatically to record my logon times into a file?

This is reasonably simple. You'll need the following kind of a script:
  @echo off & setlocal enableextensions
  echo Logon: %USERNAME% %COMPUTERNAME% %date% %time%>>C:\wherever\logon.txt
  endlocal & goto :EOF



Then
  Right-click the "start" in the lower left corner
   Choose "Explore"
    Choose the "Programs" folder
     Choose the "Startup" forlder. Create if need be.
      Click "File" in the upper left toolbar
       Click "New"
        Click "Shortcut"
         In the Wizard browse to your script
That's it. Next time you reboot, there will be an entry in your log.



If you wish to reverse the timeline, that is to have the lastest entry on top, then e.g.
  @echo off & setlocal enableextensions
  if not defined temp goto :EOF
  echo Logon: %USERNAME% %COMPUTERNAME% %date% %time%>"%temp%\logon1.tmp"
  set target_=C:\logon.txt
  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 ("%temp%\logon1.tmp" "%temp%\logon2.tmp") do if exist %%f del %%f
  endlocal & goto :EOF

Customize the destination of the log file C:\logon.txt if you do not have write permissions to the root directory of drive C:.
The logon.txt file might look someting like
 Logon: ts GARFIELD 26.10.2004 10:36:11.13
 Logon: ts GARFIELD 25.10.2004 8:33:36.79
 Logon: ts GARFIELD 24.10.2004 9:12:31.65

A sideline. The above assumes that there are no spaces in the %temp% path. It is customary to use the 8+3 format for the temp variable to avoid complications with spaces. E.g. one might have temp as
  C:\DOCUME~1\user\LOCALS~1\Temp
See item #39 for an example.

Incidentally, how does one permanently set an environment variable value in XP? (Also see item #2.)
  Right click: My Computer
  Choose Properties
  Choose Advanced
  Click "Environment Variables"
  For User variables click New
  Define Variable Value

What likewise about logout? See item #71. Just add
  echo Logout: %USERNAME% %COMPUTERNAME% %date% %time%>>C:\wherever\logon.txt
before the shutdown line.

On Windows 7 and Windows 10 navigate to %USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup and put your script (or a shortcut to it) there.



References/Comments:
  Command shell overview

[Previous] [Next]

C:\_G\WWW\~ELISANET\INFO\tscmd078.html
C:\_G\WWW\~ELISANET\FTPCMD\TSALMI.CMD /tscmd078
http://www.elisanet.fi/tsalmi/info/tscmd078.html
file:///c:/_g/www/~elisanet/info/tscmd078.html