Windows – Run Batch/CMD Upon Screensaver Activation

batchscreensaverwindows

Is there a way to run a .bat or .cmd when the screensaver starts? I've noticed some .exe can run if you rename them to .scr but is that it?

Best Answer

1. Screen Launcher

Screen Launcher lets you choose any program to run as a screensaver. You could start a Powerpoint, a movie or any EXE or associated file. To install, simply unzip, right-click and click Install on the context menu. You can then use Screen Launcher just like any other screensaver. To open files such as Powerpoint presentations, you must execute the powerpoint program and type the path to your ppt as a parameter. An example for displaying an image would be c:\winnt\system32\mspaint.exe c:\picture.bmp. Download today to take advantage of any media as a screensaver.

1

[Alternate download link since official site seems to be dead.]

2. RunSaver (don't confuse with RunScreenSaver by the same author).

Screensaver that runs a command.

2

I'm sure there are many more such screensavers that will allow you to launch arbitrary programs/scripts. But what if you'd like to continue using your current screensaver? If so, see below for the solution (tested on Win7, should work fine on Vista+).


3. Using no 3rd party tools

  1. Event ID 4802 corresponds to The screen saver was invoked, but it is not logged by default and thus we need to enable logging for this event first. So open the Local Group Policy Editor (Start / Run / gpedit.msc), navigate to:

    Computer Configuration / Windows Settings / Security Settings / Advanced Audit Policy Configuration / System Audit Policies - Local Group Policy Object / Logon/Logoff / Audit Other Logon/Logoff Events

    and enable the checkboxes for Success and Failure:

    3

  2. If you wait for your screensaver to be launched, you'll now see event logs similar to the following in Event Viewer:

    4

  3. Now it's easy to use Task Scheduler to create a task that will be launched when Event 4802 occurs. Just ensure that the Triggers tab of the task's Properties dialog looks like the following:

    5
    6

Related Question