Disable screensaver

  • Thread starter Thread starter JezB
  • Start date Start date
J

JezB

Anyone know how to disable the screensaver while a .NET (c#) windows forms
application is running, and to enable it again on exit ?
 
private Microsoft.Win32.RegistryKey regkeyScreenSaver;

private object origScreenSaveSetting;



private void Form1_Load(object sender, System.EventArgs e)

{

// Get current screen saver setting

regkeyScreenSaver = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Control
Panel").OpenSubKey("Desktop", true);

origScreenSaveSetting = regkeyScreenSaver.GetValue("ScreenSaveActive");


//Turn screen saver off

regkeyScreenSaver.SetValue("ScreenSaveActive", "0");

}

private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)

{

// Reset screen saver to original setting

regkeyScreenSaver.SetValue("ScreenSaveActive", origScreenSaveSetting);

}
 
Thanks very much - will try this.

durstin said:
private Microsoft.Win32.RegistryKey regkeyScreenSaver;

private object origScreenSaveSetting;



private void Form1_Load(object sender, System.EventArgs e)

{

// Get current screen saver setting

regkeyScreenSaver =
Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Control
Panel").OpenSubKey("Desktop", true);

origScreenSaveSetting = regkeyScreenSaver.GetValue("ScreenSaveActive");


//Turn screen saver off

regkeyScreenSaver.SetValue("ScreenSaveActive", "0");

}

private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)

{

// Reset screen saver to original setting

regkeyScreenSaver.SetValue("ScreenSaveActive", origScreenSaveSetting);

}
 
Back
Top