Trigger a batch file when a user choose “Switch User” in windows

batch-filetask-schedulerwindows 7

I save log in/out details of all the users to a text file through a .bat file, which is executed by Task Scheduler (on workstation-lock/unlock)/ gpedit.msc (on user logout/login).

I want to run the same or any .batfile when Switch User is chosen instead of log out/ workstation lock after CTRL+ALT+DEL.
The .bat file looks like

echo Logoff: %date% %time:~0,5% %UserName% >> c:\Logs\History.txt

Is there any way to do so?

Best Answer

Best choice is to configure Advanced security audit policy and windows will register for you events about:

  1. User logon
  2. Workstation lock/unlock
  3. User logout

and many others that may be useful to you.

After it you will be able to analyze, collect and generally to do with these logs everything that you see fit.

If you want something to run, then you can always set up a task scheduler that runs in the registration of a certain event in the Windows event log: when configurings scheduled task trigger you has can select to start task "when a specific event is logged". Simply select Security log and 4779 eventid.

Related Topic