Matthew Webster Posted October 1, 2005 Posted October 1, 2005 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? I'm using C#, btw. Matt. Quote
Administrators PlausiblyDamp Posted October 4, 2005 Administrators Posted October 4, 2005 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 if (Class1.IsSaverRunning()) { //Handle saver running here } Should work on all versions of windows from 98 / win2K - will not work on 95 or NT4 Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts