views:

423

answers:

2

I am writing an application in C# that plays a movie. I need to figure out how to disable the screen saver and power options using C#.

I know the Windows SDK API has a function called SetThreadExecutionState() which can be used to do this, however, I do not know if there is a better way to do it. If not, how do I incorporate this function into C#?

+3  A: 

Not sure if there is a better .NET solution but here is how you could use that API:

The required usings:

using System.Runtime.InteropServices;

The P/Invoke:

[DllImport("kernel32.dll", SetLastError = true)]
public static extern uint SetThreadExecutionState([In] uint esFlags);

And then to use it:

SetThreadExecutionState(0x00000002);

Note that I just picked one of the flags at random in my example. You'd need to combine the correct flags to get the specific behavior you desire.

Cory Charlton
+1  A: 

I found a solution here:

http://www.codeproject.com/KB/cs/ScreenSaverControl.aspx

icemanind