Run a batch/cmd upon screensaver
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.
[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.
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
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:
If you wait for your screensaver to be launched, you'll now see event logs similar to the following in Event Viewer:
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:
In order to complete the nice answer from @Karan, I would like to refer, for those interested in executing a program upon screensaver dismissing, that the process is the same used on his "3. Using no 3rd party tools" solution, but Event ID should be 4803.
(For example, in my case I want to disable Aero ("net stop uxsms") when screensaver starts, and reenable it ("net start uxsms") when screensaver stops)
If time is not terribly critical, then you could simply use the Task Scheduler's built-in Trigger "Begin the task: On Idle".
Task Scheduler -> Create Task -> "Trigger" tab -> New -> "Begin the task:" -> "On Idle"
Next, go to the "Actions" tab and set the action to whatever it is you want to run.
This should execute the Action after the screensaver starts (or if the system goes idle without the screensaver), but there may be a 0-15 minute delay. Here is the relevant specifics from the Task Scheduler documentation:
The Task Scheduler service will check if the computer is in an idle state every 15 minutes. A computer is considered to be in an idle state when a screen saver is running. If a screen saver is not running, then the computer is considered to be in an idle state if there is 0% CPU usage and 0% disk input or output for 90% of the past fifteen minutes and if there is no keyboard or mouse input during this period of time.
So, your screensaver launches, and then 0-15 minutes later windows checks for idle and launches your program.