Sunday, February 14, 2010

Automate Logoff - logon process and vice vers

Often in automation we have to deal with login to a system then logoff automatically and again login automatically. So hare I am posting ways to achive Logoff -> login automation.
- One thing one should know is even after system logoff there are process which are still executing. These process are background process or windows services.
So the trick is create an windows services or create a background process and then logoff. Now using this process you can do anything like login through windows UI using windows automation model or write a code to stimulate auto logon.
Reference link for creating service for remote sys is : http://support.microsoft.com/?kbid=251192
See also : How to logon automatically on windows startup:
open registry - HKLM->Software->Microsoft->WindowsNT->Winlogon and update the following kyes- DefaultUserName, DefaultDomainName, DefaultPassword with the logon information.

Monday, February 1, 2010

Capture Mouse button status with Desktop as whole in focus

How to get get mouse button status independent of particulat application window status.

use the following API in C#:
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern short GetAsyncKeyState(int vkey);

here vkey is ASCII key and in C# this can be found in class "Keys" or get the info from goole search.

ex.
short ke= GetAsyncKeyState((int)Keys.LButton);

If ke==0 that means Left mouse button has not ben presses since lass call of above function
If ke==1 that means Left Mouse button has been presses and released since last call of above function
Else Left mouse button is still in pressesd status.

For more information please visit: http://msdn.microsoft.com/en-us/library/ms646293%28VS.85%29.aspx

Get Keyboard state independent of an application window focus

Since a while I was looking for API to find the keyboard button status with repspect to desktop as a whole. But when I searched through Google I could find only a way to capture the keboard event whit current application in focus.
But at last I got the a way to capture the button status without any application in focus which will capture status in global.

API in C# is:
This API will provide the information staus of all the kayes on keboard
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern int GetKeyboardState(byte[] keystate);
and
this API will provide the information of apecific key.
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
internal static extern short GetKeyState(int virtualKeyCode);

For more help on this topic please visit : http://msdn.microsoft.com/en-us/library/ms646299%28VS.85%29.aspx