0

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?

Andrzej Gis
  • 13,706
  • 14
  • 86
  • 130

1 Answers1

2

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.

Community
  • 1
  • 1
Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
  • It doesn't work. The screen saver just blinks and than is replaced with log in screen. LockWorkStation(); ScreenSaverForm screensaver = new ScreenSaverForm(screen.Bounds); screensaver.Show(); I guess it may be because this screen saver is just a WinForm. Is it possible to somehow 'install' it from my application level? – Andrzej Gis Sep 21 '12 at 13:28
  • @gisek: Your assumption is most likely correct. Please check my updated answer. – Daniel Hilgarth Sep 21 '12 at 13:33