1- CloseProcessByHwnd

Closes a process that is the owner of a window with the specified handle.


Example –

Sub CloseProcessByHwnd_Example()
'The following example retrieves the handle of the Notepad window, ‘and then uses the CloseProcessByHwnd method to close the ‘notepad application.
hWnd = Window("Notepad").GetROProperty("hwnd")
SystemUtil.CloseProcessByHwnd (hWnd)
End Sub

2- CloseProcessById

Closes a process according to its Process ID (PID).

Example –

Sub CloseProcessById_Example()
'The following example retrieves the process ID of the Notepad ‘window, and then uses the CloseProcessByID method to close the ‘notepad application.
PID = Window("Notepad").GetROProperty("process id")
SystemUtil.CloseProcessById (PID)
End Sub

3- CloseProcessByName

Closes a process according to its name.

Example –

Sub CloseProcessByName_Example()
'The following example uses the CloseProcessByName method to ‘close any open instances of Notepad. If the only instances of ‘Notepad that are open are those opened by the statements below, ‘then the MsgBox displays 3.
SystemUtil.Run "Notepad.exe"
SystemUtil.Run "Notepad.exe"
SystemUtil.Run "Notepad.exe"
MsgBox SystemUtil.CloseProcessByName("Notepad.exe")
End Sub

4- CloseProcessByWndTitle

Closes all processes that are owners of windows with the specified title.

Example –

Sub CloseProcessByWndTitle_Example1()
'The following example closes all top-level windows with a titlebar ‘that contains the string "Notepad", by specifying "Notepad" as a ‘regular expression.
SystemUtil.CloseProcessByWndTitle "Notepad", True
End Sub

If you want to keep track of further articles on UFT (QTP). I recommend you to subscribe by Email and have new UFT articles sent directly to your inbox.

Subscribe to get free updates on UFT!

LearnQTP is the most popular site on UFT (formerly QTP).

Enter your first name and email address below to instantly subscribe and download an eBook on Optimizing UFT Scripts. In future, we will make sure you get new tips & tricks on UFT delivered direct to your email box.

Please check your email and confirm free subscription!