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!



5 comments:

Anonymous said...

Hi,
Found ur script while googling for similar task.
I want to get a list of all running applications by vbscript. As we can see in the "application tab" in Task manager,such list must be displayed. I tried for any namespace in WMI which supports what i need,but no luck.
Any help would be appreciated.
Thanks

Anonymous said...

Thank you exactly what I was looking for!

Sucheta said...

Thanks a lot...Just what I was looking for

che epy said...

nice and neat. thank you.

AWS Learning said...

Hi I wanted to access the application tab which is present in the Task manager.How can i do that.?