<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>Is screenserver running ?</Title>
      <Shortcut>Isscreenserverrunning?</Shortcut>
      <Description>Is screenserver running ? [C#]</Description>
      <Author>Zepho Zep</Author>
      <HelpUrl>/PreviewSnippet.aspx?SnippetID=6d39246e-bbd8-4ea7-a685-88abc1578966</HelpUrl>
      <SnippetTypes>
        <SnippetType>SurroundsWith</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet>
      <Code Language="csharp"><![CDATA[  /// <summary>
      /// Summary description for SystemParameterInfoWrapper.
      /// </summary>
      /// <remarks>
      /// A lot of this was found on 
      /// http://www.dotnet247.com/247reference/msgs/45/225361.asp
      ///note: this will only work on win 2000 or higher, NT doesn't support the screensaver running on SPI
      ///</remarks>
      public class SystemParameterInfoWrapper
      {
            public static int SPI_GETSCREENSAVEACTIVE = 16;
            public static int SPI_GETSCREENSAVERRUNNING = 114;
            private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            
            [DllImport("user32.dll", CharSet=CharSet.Auto)]
            public static extern int SystemParametersInfo(int uAction,int uParam, ref int lpvParam, int fuWinIni);
            
            public static bool IsScreenSaverRunning()
            {p; {
                  bool running = false;
                  try
                  {
                        int screenSaverRunning = -1;
 
                        // is the screen saver running?
 
                        int ok = SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, ref
                              screenSaverRunning, 0);
 
                        if (ok != 0)
                        {
                              if (screenSaverRunning != 0)
                              {p; {
                                    // screen saver is running
                                    running = true;
 
                              }
                        }
                  }
                  catch (Exception e)
                  {
                        log.Error("Exception while determining if screensaver is running",e);
                  }
                  return running;
 
            }
            public SystemParameterInfoWrapper()
            {p; {
            }
      }
]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>