Tuesday, February 7, 2012

Solution to problems with running QTP on a locked system

Refer: http://www.sqaforums.com/showflat.php?Cat=0&Board=UBB20&Number=584180

In case this page dissapears from above URL:

Quote:
I was able to overcome this problem for Web Applications.Since QTP using events which can be executed on locked box, the only real problem is dealing with dialog boxes. WinButton().Click doesn't work. To get around this problem I am using:WM_COMMAND = 273 '&H111'buttonCode - window id property for the button to clickextern.PostMessage(Hwnd, WM_COMMAND, buttonCode, 0)We run our automation nightly on locked boxes.Warning: Do not use Java Add-in 9.1 for locked execution - it will crash QTP.

############################

There is another way....you can either put this code into a .Net DLL and call it from your test script or you can modify the key in the code manually (or using VBSCRIPT) to achieve the same results.This assumes admin powers or at least enough to modify the registry key in question. I use it and it works quite nicely.Code:

public void DisableScreenTimeout(bool bEnable, int nInterval) { aTimer.Elapsed += new ElapsedEventHandler(OnDisableTimeout); // Set the Interval to nInterval seconds if (nInterval > 0) { aTimer.Interval = nInterval; } else { aTimer.Interval = 0; } aTimer.Enabled = bEnable; }
private static void OnDisableTimeout(object source, ElapsedEventArgs e) { RegistryKey regKey = Registry.CurrentUser; if (null != regKey) { regKey = regKey.OpenSubKey(@"Software\Policies\Microsoft\Windows\Control Panel\Desktop", true); if (null != regKey) { regKey.SetValue("ScreenSaveActive", 0, RegistryValueKind.String); regKey.SetValue("ScreenSaverIsSecure", 0, RegistryValueKind.String); } } }public void DisableScreenTimeout(bool bEnable, int nInterval) { aTimer.Elapsed += new ElapsedEventHandler(OnDisableTimeout); // Set the Interval to nInterval seconds if (nInterval > 0) { aTimer.Interval = nInterval; } else { aTimer.Interval = 0; } aTimer.Enabled = bEnable; }
private static void OnDisableTimeout(object source, ElapsedEventArgs e) { RegistryKey regKey = Registry.CurrentUser; if (null != regKey) { regKey = regKey.OpenSubKey(@"Software\Policies\Microsoft\Windows\Control Panel\Desktop", true); if (null != regKey) { regKey.SetValue("ScreenSaveActive", 0, RegistryValueKind.String); regKey.SetValue("ScreenSaverIsSecure", 0, RegistryValueKind.String); } } }
###################################

You can try with this part of code too.(hisudhakar.spaces.live.com)In starting of the script use SystemUtil.BlockInput, and at end of the script use SystemUtil.UnblockInput.So that QTP will lock and unlock machine in script running.You don't see the locked screen on your machine after executing SystemUtil.BlockInput. The same screen will be there but it don't accept any user input.