Friday, November 9, 2012

How to find CPU and Memory Usage using QTP

How to find out CPU utilization and Memory usage as displayed in the Windows Task Manager.

We can get these values using WMI service.


Below is the code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

'Get the CPU utilization %
myQuery = "SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name = '_Total'"
For Each objItem in objWMIService.ExecQuery(myQuery)
   print "Processor time " & objItem.PercentProcessorTime & "  %"
next

'Get the total Physical Memory
myQuery="Select * from Win32_ComputerSystem"
Set colItems = objWMIService.ExecQuery(myQuery)
For each objitem in colItems
    print "Total Physical Memory "&objitem.TotalPhysicalMemory/1024
Next

'Get the total available physical memory
myQuery="Select * from Win32_PerfFormattedData_PerfOS_Memory"
Set colItems = objWMIService.ExecQuery(myQuery)
For Each objItem in colItems
    print "Available GB: " & objItem.AvailableKBytes
Next

Wednesday, November 7, 2012

How to execute QTP scripts in a remote machine when the window is minimized?

QTP Version : 11 or later
RDP Version : 6 or later

If you want to run QTP scripts run on a remote machine and if that Remote machine/Window is minimized, then the scripts will fail.

In order to overcome the issue, you need to add a registry key in Windows registry on your client machine/from the machine where you initiating the remote desktop.
1. Close all your remote desktops.
2. Create a registry "RemoteDesktop_SuppressWhenMinimized" if does not exist in the below path:
   HKEY_CURRENT_USER\Software\Microsoft\Terminal ServerClient\RemoteDesktop_SuppressWhenMinimized
   or
   HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Terminal Server Client\RemoteDesktop_SuppressWhenMinimized
3. Set the value for this data to 2.

If you would like to add the registry key by just running a .reg file follow below steps:
1. Open Notepad.
2. Cope the below content:
 Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Terminal ServerClient\RemoteDesktop_SuppressWhenMinimized]
"RemoteDesktop_SuppressWhenMinimized"=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Terminal Server Client\RemoteDesktop_SuppressWhenMinimized]
"RemoteDesktop_SuppressWhenMinimized"=dword:00000002
3. Save the file as "FileName.reg" format
4. Now, double click on this reg file, so that registry keys will be added.