Program to turn off monitor
My requirement is to create a small application which can turn off the monitor when I press the screen lock key combination (Windows +L). This application should also turn off the machine when the screen saver is activated. It should activate the monitor again when we press any key or when I move my mouse. I am a newbie into the coding and I dont know how to do this. If you could help me to progress, it will be really helpful.
I can deploy this application to 3 of My PCs and can turn off monitors to save power.
Re: Program to turn off monitor
Turn on the Power Saving features of Windows. It will blank the monitor after x seconds, and put the pc to sleeep after x seconds
Unless you want to re-write GINA, but I think Microsoft did a good job.
Re: Program to turn off monitor
Please help me.. Turning on the power settings may not be a solution for me. I would like to power off the monitor when I press the lock key combination (Windows +L)
Re: Program to turn off monitor
I don't know of any way to do that. Can you click anything to shut off the power to the monitor? I don't think so. If you did, how would you turn it back on?
Plus, if we posted code to do so, people would be doing harm to others!
Re: Program to turn off monitor
Its really simple.. The below C# code will switch off the monitor when I click the Button in the form. And when I move my mouse or press any key, it will turn on the monitor again. But I want to make it in such a way that it should run as windows service and should turn off the monitor when the machine is locked. That all. And I am not sure how it is going to harm others.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
const uint SC_MONITORPOWER = 0xF170;
const uint WM_SYSCOMMAND = 0x0112;
const uint MONITOR_ON = 0x0001;
const uint MONITOR_OFF = 0x0002;
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hWnd, uint Msg, uint wParam, uint lParam);
public Form1()
{
InitializeComponent();
}
private void button1_Click_1(object sender, EventArgs e)
{
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF);
}
}
}
Re: Program to turn off monitor
Something like this? It still doesn't hook into windows security system (GINA)
Code:
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Private Const EM_GETLINECOUNT = &HBA
Private Sub Text1_Change()
Text1.Height = Me.TextHeight("A") * SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0, 0)
End Sub
Re: Program to turn off monitor
It does not work SendMessage returns zero on using the monitor command.
At least at my system. Maybe not all monitors support this shutting off.
Re: Program to turn off monitor
VB6 does not do windows services so you are barking up the wrong tree in this section of the forum.
You would need to use VB.Net, C# or C++ to create the service.
First step of course would be to create a windows service project. It is possible that there may be a hook in there somewhere that would allow you to tell when the system was locked. I honestly have never looked to see if such a thing exists.
Re: Program to turn off monitor
not likely. people have tried to hack GINA for decades
Re: Program to turn off monitor
Didn't even know GINA exists. What is she like? ;)
The project was not necessarily said to be a service. If the above function call would have worked, a standard application should do the trick.
Re: Program to turn off monitor
Quote:
Originally Posted by
WoF
The project was not necessarily said to be a service. If the above function call would have worked, a standard application should do the trick.
Actually he said he wanted it to be a service, hence my previous response.
Quote:
Originally Posted by arbrahul
But I want to make it in such a way that it should run as windows service and should turn off the monitor when the machine is locked.
Re: Program to turn off monitor
>VB6 does not do windows services so you are barking up the wrong tree in this section of the forum.
Well Mr. Miser, here you are wrong as VB6.0 CAN DO SERVICES! Albiet not very well but it can.
http://www.smsoft.ru/en/ntservice.htm
http://www.vbrad.com/article.aspx?id=92
http://articles.techrepublic.com.com...1-1049775.html
Re: Program to turn off monitor
Really? I had looked into this a while back and could find nothing on it.
I will look into the links you have provided. Thanks. :)
Re: Program to turn off monitor
@DataMiser: You were right. :) I only saw:
"My requirement is to create a small application which can turn off the monitor ..."
Nevertheless, I suppose SendMessage would not work in a service either, if it refuses already in a usual application.
Re: Program to turn off monitor
Quote:
Originally Posted by
WoF
Didn't even know GINA exists. What is she like? ;)
http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx
Debugging:
WLX_SAS_ACTION_NONE
WLX_SAS_ACTION_LOCK_WKSTA
WLX_SAS_ACTION_LOGOFF
WLX_SAS_ACTION_PWD_CHANGE
WLX_SAS_ACTION_TASKLIST
WLX_SAS_ACTION_SHUTDOWN_REBOOT
WLX_SAS_ACTION_SHUTDOWN
WLX_SAS_ACTION_SHUTDOWN_SLEEP
WLX_SAS_ACTION_SHUTDOWN_HIBERNATE
WLX_SAS_ACTION_SHUTDOWN_POWER_OFF