Link to home
Create AccountLog in
Avatar of FamousMortimer
FamousMortimerFlag for United States of America

asked on

VB.NET - Sleep/Wake Monitor from Windows Service Application

Hi Experts,

The title says it all pretty much.

I am trying to create a windows service that can sleep and wake a monitor.

Avatar of OriNetworks

Simple google search...

public partial class Form1 : Form
    private int SC_MONITORPOWER = 0xF170;
    private uint WM_SYSCOMMAND = 0x0112;

    static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

    public Form1()

    private void button1_Click(object sender, EventArgs e)
        SendMessage(this.Handle, WM_SYSCOMMAND, (IntPtr)SC_MONITORPOWER, (IntPtr)2);

Open in new window

Avatar of FamousMortimer


Well I am using VB and i do not have any forms so this needs to be run from a module.  I have the equivalent VB code

<Runtime.InteropServices.DllImport("user32.dll")> Public Function SendMessage(hWnd As Integer, hMsg As Integer, wParam As Integer, lParam As Integer) As Integer
    End Function

SendMessage(Me.Handle.ToInt32(), WM_SYSCOMMAND, SC_MONITORPOWER, -1)

Open in new window

This does not work in the module, especially because Me.Handle is not valid in a module.
Avatar of FamousMortimer
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
it works