Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

  • Administrators
Posted

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

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...