Home > OS >  Launch ZAP using a script if not already running
Launch ZAP using a script if not already running

Time:07-15

I launch ZAP with a python script using subprocess:

filePath=r"C:\\Program Files\\OWASP\\Zed Attack Proxy\\zap-2.11.1.jar"
subprocess.Popen(filePath, shell=True, stdout=subprocess.PIPE)

This script works fine and launches ZAP. However, I'd like to have a check whether the app is already running and if so, not to launch it again. I took a look how could this be achieved in python and realized I could use a check for running processes. Problem is that the process runs as Java(TM) Platform SE binary in Task Manager so checking for that one might not be the best solution. Any idea how to solve this would be appreciated. Aiming for python/ps script. Thank you!

CodePudding user response:

A simple workaround would be to simply grab all titles of current processes and if it happens to find zap amongst them then break

or just have a flag set if it finds it as follows:

import subprocess
import pyautogui
global marker
marker = False

for window in pyautogui.getAllWindows():  
    if window.title == "OWASP ZAP":
        marker = True
if marker:
    filePath=r"C:\\Program Files\\OWASP\\Zed Attack Proxy\\zap-2.11.1.jar"
    subprocess.Popen(filePath, shell=True, stdout=subprocess.PIPE)
  • Related