| 1. |
Solve : How to check if a program is running in cmd?? |
|
Answer» So I'm writing some python and I want to make an if statement that checks if a program is RUNNING I figured the simplest way would be to use subprocess and check with cmd if the program is running. Since the program needs to be running at all times, it would also be ideal to have it start the program if it is not running. So I'm writing some python and I want to make an if statement that checks if a program is running I figured the simplest way would be to use subprocess and check with cmd if the program is running. I found this python code that uses WMI to get a list of processes on Win32. Code: [Select]import win32com.client strComputer = "." objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator") objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2") colItems = objSWbemServices.ExecQuery("Select * from Win32_Process") for objItem in colItems: PRINT "NAME: ", objItem.Name print "File location: ", objItem.ExecutablePath |
|