Jump to content

Replicating KillScreenSaver() in AutoIT (programatically end screen saver)


Recommended Posts

I did a forum search for screensaver and checked out the first 5 pages. A couple of these were about calling the screensaver, the rest were about creating a screensaver. If I missed the post about terminating the screensaver, I apologize.
To start the default screensaver, I tweaked the example from the AutoIt _SendMessage documentation. Rather than SC_MONITORPOWER, I'm using SC_SCREENSAVE = 61760, and I dropped the on/off parameter. 

I want to later kill the screensaver. I imagine I can do so by faking mouse or keyboard input, however I'd prefer to avoid that and based on some reading it doesn't look like that method works on Windows 8+ (my guess is that this is because the secure desktop is active but were sending input to the user desktop, I could be way off base here).

So, research has led me to MS Article 140723 - Force a screen saver to close and CodeProject - Controlling The Screen Saver With C#
The MS example has 

PostMessage (GetActiveWindow(), WM_CLOSE, 0, 0L);

But based on other comments in that article, I don't think that'll work in Win7 because the screensaver is running in one of the secure desktop(s), rather than the users desktop. The Microsoft example has a code-block example of how to work around this, but I'm not sure how to take that example and convert it for use within AutoIt. I'm also worried about running that postmessage to the activewindow, because I don't want it to inadvertently close my app. Haha. 

 

Why am I trying to do this nonsense? I have a task that kills logonui.exe on the secure desktop to refresh the OOBE defaultBackground. Attempts to start logonui.exe directly have failed, but Winlogon.exe will start logonui.exe if 1) The SAS is triggered, or 2) the default screensaver is exited.

Link to comment
Share on other sites

So, digging into the ScreenSaverProc function a bit, found this:

Quote
WM_ACTIVATE Terminate the screen saver if the wParam parameter is set to FALSE.


Microsoft: Handling Screen Savers

It suffers the same fate as GetActiveWindow() in that it only works in the very (post-XP days) select circumstance that the screensaver is not generated on its own desktop. In that select circumstance, the screensaver is launched on the same desktop as that the script is running on, so the script can grab the handle and close it.

Another really good note on the topic is Bob Moore - How do I start, detect and stop screen savers?

Found an interesting thread about Switching Desktops using WinAPI in AutoIt that looks helpful for switching to the 'screensaver' desktop. Just struggling to see how it all goes together.

 

Link to comment
Share on other sites

38 minutes ago, Bert said:

is there some reason you can't run a powershell script to do what you need on the locked desktop?

I'm not necessarily opposed to it. The biggest hindrance I've found with powershell right off the bat is the executionpolicy. So my choices are to start self-signing and get that set up on multiple machines, OR run unrestricted. The next is the learning curve of actually picking up powershell. 

In this case, I have no guarantee that getting past both of those obstacles will then lead to an ultimate success. It might be possible with powershell, but I know that this will work.
I actually just got this running, though not how I'd hoped. I can set the parameters for the screensaver, use sendmessage to call it, terminate LogonUI, then terminate the screensaver's process. Doing this causes WinLogon to restart LogonUI, which pulls an updated OOBE defaultbackground that I've generated.

While that method works, I'm still interested in properly sending WM_CLOSE to the screensaver. It may not be a popular request, but the threads are out there.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...