Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

How can I get a list of the open windows on the taskbar in Silk4Net and SilkTest Workbench?

How can I get a list of the open windows on the taskbar in Silk4Net and SilkTest Workbench?

There is no inbuilt function for this. You will need to enumerate all of the running processes and then ascertain which of those processes has an open GUI. The following code module will do this for you:

Module modGetAllOpenWindows
	' Unmanaged API calls
	Public Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As EnumWindowsProcByVal lParam As Int32As Int32
	Public Declare Function IsWindowVisible Lib "user32.dll" (ByVal hwnd As IntPtrAs Boolean
	Public Delegate Function EnumWindowsProc(ByVal hwnd As IntPtrByVal lParam As Int32As Boolean
	Public Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hwnd As IntPtrByVal lpString As StringByVal cch As Int32As Int32
	Public Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hwnd As IntPtrAs Int32
	Public Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hwnd As IntPtrByVal nIndex As Int32As Int32
	Public Declare Function GetParent Lib "user32.dll" (ByVal intptr As IntPtrAs IntPtr
	Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hWnd As IntPtrByRef lpRect As RECTAs Boolean
	' Public constants
	Public Const GWL_HWNDPARENT As Int32 = -8
	' Public function
	Public newWindowList As List(Of String)
	' Private function
	Private newHandleList As List(Of IntPtr)
	' Structure - checks for a GUI
	Private Structure RECT
		Public left As Integer
		Public top As Integer
		Public right As Integer
		Public bottom As Integer
		Public Sub New(ByVal _left As IntegerByVal _top As IntegerByVal _right As IntegerByVal _bottom As Integer)
			left = _left
			top = _top
			right = _right
			bottom = _bottom
		End Sub
	End Structure
	' -----------------------------------------------------------
	' Enumerate the running processes - discard any that does not have a GUI
	' -----------------------------------------------------------
	Private Function EnumWinProc(ByVal hwnd As IntPtrByVal lParam As Int32As Boolean
		Dim sWindow As String = Nothing
		If IsWindowVisible(hwnd) Then
			If GetParent(hwnd) = IntPtr.Zero Then
				If GetWindowLong(hwnd, GWL_HWNDPARENT) = 0 Then
					sWindow = String.Empty.PadLeft(GetWindowTextLength(hwnd) + 1)
					GetWindowText(hwnd, sWindow, sWindow.Length)
					If Not String.IsNullOrEmpty(sWindow.Substring(0, sWindow.Length - 1)) Then
						newWindowList.Add(sWindow.Substring(0, sWindow.Length - 1))
					End If
				End If
			End If
		End If
		EnumWinProc = True
	End Function
	' -----------------------------------------------------------
	' Start the enumeration process
	' -----------------------------------------------------------
	Public Sub RefreshWindowList()
		newWindowList = New List(Of String)
		EnumWindows(AddressOf EnumWinProc, CInt(True))
	End Sub
End Module

To call the module add the following code to your testcase:



The list of open windows is written to newWindowList. You can loop through the array and recover the window names as required. For example, the following code will call the enumeration process and then prints the open windows to the results file:

		For Each item As String In newWindowList

The results output will depend on your system but as an example it will look something like this:


getOpenWindows (Running) - Microsoft Visual Studio (Administrator)
Q-Dir 5.04
Inbox - Mailbox - [redacted] - Microsoft Outlook
Program Manager



Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-04-17 04:58
Updated by:
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.