from win32com.client import GetObject def getPID(name): """Returns the PID of a given process.""" WMI = GetObject('winmgmts:') processes = WMI.InstancesOf('Win32_Process') process_list = [(p.Properties_("ProcessID").Value, p.Properties_("Name").Value) for p in processes] for process in process_list: if process[1] == name: print("PID of '" + name + "': " + str(process[0])) return process[0]