Test automation

Test automation
AUtomation

Monday, June 16, 2008

Simple VB Script to check if Application is already running

There are certain situations where you can't run two instances of same application OR before starting a test with QTP, you want out find out whether a particular process is already running. Ex: In case of Siebel Automation . To find the process, the workflow is, Go to "Windows Task Manager"[Ctrl-Shift-Esc] > Process tab > strain your eyes to sift the required process from the 100's of already running processes.
We can do this job with a simple VBScript. This will reduce the duration of workflow to < 2 sec and you get the result instantly at the click of a button.

Code:
Dim AllProcess
Dim Process
Dim strFoundProcess
strFoundProcess = False

Set AllProcess = getobject("winmgmts:") 'create object
For Each Process In AllProcess.InstancesOf("Win32_process") 'Get all the processes running in your PC
If (Instr (Ucase(Process.Name),"TASKMGR.EXE") = 1) Then 'Made all uppercase to remove ambiguity. Replace TASKMGR.EXE with your application name in CAPS.
msgbox "Application is already running!" 'You can replace this with Reporter.ReportEvent
strFoundProcess = True
Exit for
End If
Next
If strFoundProcess = False Then
msgbox "Go ahead!Application is not running" 'You can replace this with Reporter.ReportEvent
End If
Set AllProcess = nothing


To check whether this is working:
1) Copy the above code to a notepad and save file as test.vbs on your desktop.
2) Open the Windows Task Manager[Ctrl-Shift-Esc].
3) Double click on file created above(test.vbs)
4) You should get a message "Application is already running!"
5) Done...Enjoy!