Andrzej Gis
Andrzej Gis

Reputation: 14306

Launch a custom screensaver + lock machine

In my application I'd like to accomplish 2 things when a user wants to take a break and clicks a log out button.

  1. Lock the machine
  2. Launch a custom screen saver that would show the time the user is logged out.

I managed to do the lock easily by:

[DllImport("user32.dll")]
private static extern void LockWorkStation();

I found a tutorial on how to make a custom screen saver. I downloaded the sample code and it worked fine. But when I added the LockWorkStation(); line it killed the screen saver.

Can you help me with this or suggest a workaround?

EDIT

This screen saver from tutorial is just w WinForm. Should I somehow install it to the system? Is it possible form my application level?

Upvotes: 0

Views: 605

Answers (1)

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174299

The solution most likely is the following:

  1. Lock the workstation
  2. Show the screensaver

For the second step, the following is important:

You application is simply a program showing a window. As such any windows it tries to show are not shown to the user when the workstation is locked.
Your window will only be shown when you register your program as a real screensaver, set it as the current screensaver and than start it, for example using the SC_SCREENSAVE message.

Upvotes: 2

Related Questions