How to prevent desktop from locking

11 02 2012

Generally in corporate world our desktop gets automatically locked after a few minutes of inactivity. We will not be able to change this property. But in some situations we might need to schedule our application to run after some time and that application run only when the system is unlocked. That means we have to keep the system without locking even if there is no activity.

We can create a simple mouse move simulator application to establish this. No need to move the mouse actual position. We can send the same mouse position in a particular time interval.
To send mouse move message to system, windows provides an API SendInput. The second parameter of this function is a pointer to the structure INPUT, which decides an event to be inserted into the keyboard or mouse input stream.
From our sample application we can start a Timer using Win 32 API SetTimer and timeout value should be less than system locking timeout value.

PreventDesktopLockingDlg.cpp

PreventDesktopLockingDlg.h

 

void SendMouseMoveMessage()
{
	INPUT i;

	i.type = INPUT_MOUSE;
	i.mi.dx = 0;
	i.mi.dy = 0;
	i.mi.mouseData = 0;
	i.mi.dwFlags = (MOUSEEVENTF_MOVE || MOUSEEVENTF_ABSOLUTE);
	i.mi.time = 0;
	i.mi.dwExtraInfo = GetMessageExtraInfo();
	SendInput(1, &i, sizeof(i));
}

If you want to hide this sample application to taskbar please see one of the oldest post.

Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: