Re: [AMMRL] Windows 11 and log files

From: Bridget Becker via groups.io <babecker=mit.edu_at_groups.io>
Date: Wed, 7 Jan 2026 19:34:55 +0000

Hello Anne,

To implement the logon and log off scripts Walt indicated, add them to the
group policy. Search for and open the group policy editor within windows.
Then under User Configuration -> Windows Settings -> Scripts (logon/logoff),
click on logon or logoff, then Display Properties. In the properties box if
you click show files it will open a windows explorer to the location where
it would be most convenient to save the scripts (which are batch files --.bat).
Then click the add... button in the properties box and select the script to
apply. You will have to have administrator privileges to add your script.

For one of our instruments the user accounts ended up with a different date
format so I had to write a more robust version of the logon/log off scripts
which should save the date/time regardless of any local date/time settings
for each user account. This is important in our case for our linux scripts
to parse the log files. You can edit the script in notepad just be sure to
save as .bat file not a .txt (default) file. Replace the path\to\logons.txt
with your desired path and make sure that it exists and can be written to.

After you have set up the script you should be able to log off and back on
and see these events written to the logons.txt (or your chosen file name).

Here is the body of the more robust logon script:

_at_echo off
:: Set day of week abbreviation, look up numeric day of week and set day name based on look up table
for /f "tokens=2 delims==" %%a in ('wmic path win32_localtime get dayofweek /format:list') do set dayOfWeek=%%a

set day=%dayOfWeek:~0,1%

set "DayNames=Mon Tue Wed Thu Fri Sat Sun"
for /f "tokens=%dayOfWeek% delims= " %%b in ("%DayNames%") do (
   set "CurrentDayName=%%b"
)

:: Get the region independent date time and set each variable in the date and time
for /f "tokens=2 delims==" %%G in ('wmic os get localdatetime /value') do set datetime=%%G

set year=%datetime:~0,4%
set month=%datetime:~4,2%
set day=%datetime:~6,2%
set hour=%datetime:~8,2%
set minute=%datetime:~10,2%
set secs=%datetime:~12,2%
set milsec=%datetime:~15,2%

:: Now echo the format for the logon/off scripts

echo %USERNAME% logged on at %CurrentDayName% %month%/%day%/%year% %hour%:%minute%:%secs%.%milsec% >> c:\path\to\logons.txt

Bridget Becker
Research Specialist
Department of Chemistry Instrumentation Facility
Massachusetts Institute of Technology
77 Mass. Ave. Rm: 18-0080
Cambridge, MA 02319
(617) 253-1812



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#3112): https://urldefense.com/v3/__https://ammrl.groups=
.io/g/main/message/3112__;!!PvDODwlR4mBZyAb0!R2gC0IpR50_goKmxDVYFBWpxma4ghi=
MVYxGi2pseP1YwKRLNzEgrDvCSG4ipI1HwihKKOtXw7UKnnBdmdEIAXkYDCr-i$
Mute This Topic: https://urldefense.com/v3/__https://groups.io/mt/117137101=
/7559972__;!!PvDODwlR4mBZyAb0!R2gC0IpR50_goKmxDVYFBWpxma4ghiMVYxGi2pseP1YwK=
RLNzEgrDvCSG4ipI1HwihKKOtXw7UKnnBdmdEIAXk0AVn7O$
Group Owner: main+owner_at_ammrl.groups.io
-=-=-=-=-=-=-=-=-=-=-=-




Received on Thu Jan 08 2026 - 04:31:56 MST

This archive was generated by hypermail 2.4.0 : Mon Feb 09 2026 - 16:54:28 MST