using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32;
using System.Runtime.InteropServices;
namespace MonitorPowerSetting
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
int HWND_BROADCAST = 0xFFFF;
int WM_SYSCOMMAND = 0x0112;
int SC_MONITORPOWER = 0xF170;
[DllImport("user32.dll")]
private static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);
/*
Start the registry editor (regedit.exe)
Move to HKEY_USERS/.DEFAULT/Control Panel/Desktop
Double click PowerOffActive and set to 1. Click OK
Double click ScreenSaveActive and set to 1. Click OK
Double click SCRNSAVE.EXE (if present) and set to "(NONE)" (don't type the quotes). Click OK
Move to HKEY_USERS/.DEFAULT/Control Panel/PowerCfg
Double click CurrentPowerPolicy and set to 0 (the Home/Office Desk power setting configuration). Click OK
Close the registry editor
Reboot the machine
To change the settings such as monitor timeout change the settings on your local profile, export HKEY_CURRENT_USER/Control Panel/PowerCfg/PowerPolicies/0 to a file and import to HKEY_USERS/.DEFAULT/Control Panel/PowerCfg/PowerPolicies/0.
If you need to do this on lots of machines create a .reg file and push via a login/startup script (which can be specified via Group Policy).
*/
private void btnTurnOff_Click(object sender, RoutedEventArgs e)
{
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2);//DLL function
}
private void btnOneMin_Click(object sender, RoutedEventArgs e)
{
}
private void btnNormal_Click(object sender, RoutedEventArgs e)
{
RegistryKey hklm = Registry.Users;
RegistryKey subkey = hklm.OpenSubKey(@".DEFAULT", false);
subkey = subkey.OpenSubKey(@"Control Panel", false);
subkey = subkey.OpenSubKey(@"PowerCfg", true);
subkey.SetValue("CurrentPowerPolicy", "0");
}
}
}