screensaver/workstation lock detection

Joined
Feb 14, 2004
Messages
11
Location
London
Does anyone know if it is possible to detect when/if the workstation is locked (Win+L) and/or when the screensaver is activated?

Is there a call to make, say, every 5 seconds which could check the status of such functions?

Im using C#, btw.

Matt.
 
C#:
public class Class1
{
[DllImport("user32.dll", EntryPoint="SystemParametersInfo", SetLastError = true)]
public static extern bool SystemParametersInfo(uint action, uint param, ref int vparam, uint init);
const int SPI_GETSCREENSAVERRUNNING = 0x0072;

public static bool IsSaverRunning()
{
	int IsRunning = 0;
	SystemParametersInfo(SPI_GETSCREENSAVERRUNNING,0,ref IsRunning,0);
			
	if (IsRunning==0) 
		return false;
	else 
		return true;
	}
}
}

this can be called from a standard windows timer or similar like
C#:
if (Class1.IsSaverRunning())
{
//Handle saver running here
}

Should work on all versions of windows from 98 / win2K - will not work on 95 or NT4
 
Back
Top