views:

28

answers:

1

Hi,

I'm writing a screensaver in C# which should launch an application and then terminate when the user presses the "A" key.

This currently does happen on Windows 7 when you double click the .scr file or wait until it launches. On Windows XP the external application launches normally only when you double click the .scr file. When the screensaver is launched by the OS, then pressing "A" does terminate the screensaver but the external application is launched momentarily then closes. The Task Manager shows that the external application closes a split second before the Screensaverso I would imagine that this terminates the external application too for some reason. This is the behaviour with whatever you set the external application to be.

Is there something internal that happens when a Screensaver is launched from the OS rather than double clicked by the user?

I'm using System.Diagnostics.Process.Start() to run the external application but using Process and ProcessStartInfo has the same effect.

I'm using .NET Framework 3.5

Regards, Frank

+1  A: 

Yes, a screen saver runs in its own desktop. There are three common ones, the login desktop, the one you are looking at now and the screen saver desktop. A process is associated to a desktop through the STARTUPINFO.lpDesktop member passed to CreateProcess. When NULL, it runs in the current desktop.

a desktop cannot be closed until all processes that run on it are closed. Which is what you see happening done automatically. Not sure why you are trying to do this but you're looking at pinvoking CreateProcess to avoid getting this process killed. I do rather doubt that Windows allows this, screen savers were a notorious vector for malware.

Hans Passant
Just had a look on MSDN which says "Whenever a secure screen saver activates, the system automatically switches to the ScreenSaver desktop, which protects the processes on the default desktop from unauthorized users. Unsecured screen savers run on Winsta0\Default". Is the screensaver secure when you select "On Resume, password protect?". Either way the external application shuts down.
FrancisCastiglione
It is indeed impossible to send messages across desktops.
FrancisCastiglione