site
stats
By Anish Pillai Anish Pillai Posted under QTP Basic Stuff | QTP Concepts

UFT Batch Run – Prevent Windows from getting locked during Script Execution

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×

We had previously talked about a method whereby you can use Windows Media Player to prevent Windows from getting locked while your QTP/UFT batch run is in progress. Here are few more alternative methods you can use to make this work

 

1. Use VBScript SendKeys to simulate keypress at regular intervals

Copy the below code in a text file and save it with a .vbs extension

Dim durationInMins
Set obj = CreateObject("WScript.Shell")

'Capture the input from user
durationInMins = InputBox ("Enter time (in minutes) for which machine needs to remain unlocked" & vbCrLf & vbCrLf & "Enter 0 for indefinite time","Enter Duration")

If durationInMins > 0 Then
	'Run For loop for the duration specified by the user
	For i=1 to durationInMins
		WScript.Sleep (60*1000)
		obj.SendKeys ("{CAPSLOCK 2}")
	Next
ElseIf durationInMins = 0 Then
	'Run indefinite Do loop
	Do
		WScript.Sleep (60*1000)
		obj.SendKeys ("{CAPSLOCK 2}")
	Loop
End If

When you open this VBScript file in your machine, it will display a popup where you will need to specify the time (in minutes) for which Windows needs to remain unlocked. Enter 0 if you want this utility to run indefinitely. Entering a specific time limit rather than 0 is useful in scenarios where you don’t want the machine to keep running unnecessarily.

For example, consider a scenario where you want to execute a nightly batch run. And you know, by previous experience, that the UFT would take around 2-3 hours to complete the batch execution. In such a case, it will be good to specify the time in the alert box as 180 or 200, so that the machine comes to normal mode after this time duration and gets locked or shutdown.

How this code works

This code simply uses VBScript SendKeys method to simulate keyboard key press every one minute; thereby preventing windows from getting locked. Here we are using CAPS LOCK key to simulate the key press, using the code – SendKeys (“{CAPSLOCK 2}”).

You would have noticed the number 2 next to CAPSLOCK. This means that the CAPSLOCK key is pressed twice in very quick succession. This makes sure that CAPSLOCK remains in the same state and doesn’t interfere in your work in any way.

There are many other flavors of this code, in which people use different keys such as SCROLLLOCK, NUMLOCK, F15 etc. All these work fine without any issues and you can use any of these if you would want to modify the code.

 

2. Using 3rd party software

There are many 3rd party software (many with source code), which simulate keypress or mouse movements to keep your machine unlocked. Couple of them which I have used in the past are –

Mouse Jiggler – This software works by jiggling the mouse pointer back and forth

Caffeine – Another useful utility which simulates F15 keypress to prevent windows getting locked

 

3. Plug and Use USB devices

While searching on the internet, I came across these USB devices which create constant mouse activity so your computer won’t go idle. You can search on Amazon if you want to have a look at these USB devices.

These were all the different methods that I have heard of and tried (except Pt 3 – Plug and Use USB devices) on my own. You can even integrate these utilities with your UFT/QTP frameworks to provide more power to your automation frameworks.

Have you used any other piece of code or utility, which is not covered here? Let us know about it in the comments section.

 

If you enjoyed this article, you can join our blog to get new articles delivered directly in your inbox.

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×
0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×