Setting up screensaver via CSharp/C# application

  • Thread starter Thread starter Ron Nanko
  • Start date Start date
R

Ron Nanko

Hi,

I'm trying to setup a screensaver via a C# application. What I
currently do is this:

[DllImport("user32", CharSet=CharSet.Auto)]
unsafe public static extern short SystemParametersInfo (int uiAction,
int uiParam, int* pvParam, int fWinIni);
....
try
{
RegistryKey oKey = Registry.CurrentUser.OpenSubKey("Control Panel",
true);
oKey = oKey.OpenSubKey("desktop", true);
oKey.SetValue("SCRNSAVE.EXE", in_sSaver);
oKey.SetValue("ScreenSaveActive", "1");

unsafe
{
int nX = 1;
SystemParametersInfo(
SPI_SETSCREENSAVEACTIVE,
0,
&nX,
0
);
}
}
catch (Exception exc)
{
System.Windows.Forms.MessageBox.Show(exc.ToString());
}

However, when I execute this code and change to the MS Windows Display
Propert ies (Screensaver tab), the current screensaver is always set
to "none".

In the registry under HKCU/Control Panel/Desktop both SCRNSAVE.EXE and
ScreenSaveActive are set properly.

What is wrong?

Thanks in advance,
Ron
 
Thanks, but that's not what I was looking for - the article seems to
describe how to write a screensaver, while I need to set an existing
screensaver up via a C# application!
 
Just in order to answer my own question: the solution was rather
simple. My custom screensaver's filename had more than 8 characters,
obviously Windows messes things up then. I shortened it to 8 characters
and everything worked fine.
 
Back
Top