title: To read/set a user screensaver on Windows, do I need to use system registry or SystemParametersInfo API?
body: <p>There seems to be two methods of setting and getting a user screensaver parameters on a Windows platform:</p>
  
  <p>1: Via the SystemParametersInfo() API:</p>
  
  <pre><code>//To read
  SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, &amp;bScreensaverAcrtive, NULL);
  SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0, &amp;nScreensaverTimeout, NULL);
  //No API to get the screensaver file used
  
  //To set
  SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 0, bScreensaverAcrtive, NULL);
  SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, 0, nScreensaverTimeout, NULL);
  //No API to change the screensaver file
  </code></pre>
  
  <p>2: Through the system registry keys:</p>
  
  <pre><code>HKCU\Control Panel\Desktop - "ScreenSaveActive"
  HKCU\Control Panel\Desktop - "ScreenSaveTimeOut"
  HKCU\Control Panel\Desktop - "SCRNSAVE.EXE"
  </code></pre>
  
  <p>But since there're two competing methods that seem to do the same, what is the recommended way to use?</p>
  
  <p>PS. I highly favor method #2 (or writing directly into registry) due to the following reasons:</p>
  
  <p>A. If you read the explanation of a bug in the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms724947%28v=vs.85%29.aspx" rel="nofollow">SPI_GETSCREENSAVEACTIVE flag</a>, you'll see that MS themselves <a href="http://support.microsoft.com/kb/318781" rel="nofollow">recommend</a> to use registry.</p>
  
  <p>B. If you read the documentation for the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms724947%28v=vs.85%29.aspx" rel="nofollow">SPI_SETSCREENSAVEACTIVE</a> and <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms724947%28v=vs.85%29.aspx" rel="nofollow">SPI_SETSCREENSAVETIMEOUT</a> flags, there's this mystical line that says, "*If the machine has entered power saving mode or system lock state, an ERROR_OPERATION_IN_PROGRESS exception occurs.*" I first ignored this situation until it actually started happening on my test installation of Windows 8. This is the most asinine error, I should tell you. There's absolutely no graceful way of interpreting what it means or do any workaround (except, writing directly into the registry.)</p>