Monday, November 23, 2009

Monitor Power Saver


Nearly all of us employ some power saving scheme while working with our PCs' like, switching off the monitors (physically); setting the screensavers to kick in after a preset duration, putting the system to stand-by or totally powering down the system.

Consider this scenario - you want to take a 5 minute break and your screensaver is set to kick in around 3 minutes. You don't want to put the system to stand-by or totally power down the system as the lag required to get the system up and working is bit annoying. (You may have set up an antivirus scan, update or download which you don't want to be bothered with while you power down). So, your best bet is to power down the monitor for the 5 min and switch it on when you are back or let the screensaver kick in (which would give you only (5-3) 2 minute of power saving).

Switching on and off (physically) the power switch of your monitor isn't a great idea, because on a long run it can damage the switch (Monitor switches aren't meant to take heavy duty switch on and off cycles. Present day monitors are so designed to be left on for hours, while the power saving strategy has to be implemented by the installed softwares).

Well, this was one question that has been bothering me quiet recently. Thankfully a quick google search took me to the right direction. Below I've provided a small program (in C++), that could help solve a situation like the one described above.

// PROGRAM TO TURN OFF MONITOR IN C++

#include
using namespace std;

int main()
{
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) 2);
return 0;
}

//EOF

The source code and executable can be downloaded here (6.40 KB).
(Open the link in new tab/window and save file as PowerSaver.rar)

A little light on the SendMessage function.

LRESULT SendMessage(
HWND hWnd, // handle of destination window
UINT Msg, // message to send
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);

The SendMessage function sends the specified message to a window or windows. The function calls the window procedure for the specified window and does not return until the window procedure has processed the message.

Parameters:
hWnd - Handle to the window whose window procedure will receive the message. If you don't want to bother creating a window to send the message to, you can send the message to all top level windows (HWND_BROADCAST) or you can use GetDesktopWindow function sending the message to the desktop window.
Msg - Specifies the message to be sent (WM_SYSCOMMAND).
wParam - Specifies additional message-specific information (SC_MONITORPOWER).
lParam - Specifies additional message-specific information.
1 - the display is going to low power.
2 - the display is being shut off.
-1 - the display is being turned on (undocumented value).

This program should compile with almost any C compilers without any errors, to give you an efficient monitor friendly power management application.

When the program is executed it forces the display to go into 'power off' state and (program) is terminated. Upon mouse movement or keyboard activity, the display is restored.

Try linking the program with any key on your keyboard (multimedia keyboard) or put a shortcut to the program on your desktop or assign a keyboard shortcut for the program.

Thanks to all people out there who helped me with this program.

Friday, August 28, 2009

Who is in control?


Is it you or your OS or some non-responding program?

Quiet often I've come across questions like
- recently my computer have been real slow, like some application is taking up all the memory
- some annoying window keeps popping up every time I do this/that (or at start-up)
- my anti-virus/anti-spyware detects some infected file, but I can't find or delete it
- I'm not able to delete some file on my hard-disk, it says 'file in use'
and the list goes on...

Well, if you have come across some of these warnings go ahead.

Any problem can be effectively solved if you get to the root of the problem and for a computer user, getting to the root of the problem would equally mean identifying which application caused the problem and its exact location. This is exactly where Process Explorer comes in.

Process Explorer is one of the most powerful application available for Windows, one which gives you full details about all running applications at any instant. It is a freeware created by Sysinternals, which was recently acquired by Microsoft Corporation. Almost similar to Task Manager in Windows, the Process Explorer is much more powerful and efficient.


Screenshot 1 - Process Explorer main window


Screenshot 2 - Process Explorer system information

A few good reasons why you should try out Process Explorer

- To track down problems (use Find to list or search for resources, held by a process)
- Can be used to track down what is holding a file open and preventing its use by another program
- Find complete location and command line of a running application (Command Line)
- To find a process that is maxing out the CPU or the amount of resources used by a process (R.Click and Properties)
- Real time system activity and resource utilization (Ctrl+I)
- Pointing the mouse in the graph of CPU Usage in System Information gives the applications utilizing the CPU
- CPU activity graph for each process (R.Click any > Properties > Performance Graph)
- Suspend, kill or restart a selected process or process tree
- Use Window Title to detect open applications and status at Window status

These are just a few, but the real potential is much more. Just work with it a couple of times (advisable coz it is always good to differentiate between the legitimate applications from illegitimate ones and this comes with experience).

Process Explorer can also be triggered to open up instead of Task Manager when you press 'Ctrl+Alt+Del' and can also be fully customised to show the parameters you want.

There is no installation required, just download from the site (link given below), unzip and run the exe.

More Reading:
http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx (Download link here)
http://en.wikipedia.org/wiki/Process_Explorer