Hi Guys,
Given below is the function i have defined to find process id of the running process xyz.exe. But when i try to run this function when the process xyz.exe is not running, obviously "pid = p[0].Properties_('P rocessId').Valu e" shows error as the process doesn't exist.
but i want it to return pid="" ,to use that value to check if the process is running or not.I am now managing with a try block to catch the exception and return pid="".but this looks bit awkward.
So would like some experts to pitch in with some idea to implement something more elegant.
[CODE=python]from win32com.client import GetObject
WMI = GetObject('winm gmts:')
def getPid():
pid = ""
p=None
processes = WMI.InstancesOf ('Win32_Process ')
p = WMI.ExecQuery(' select * from Win32_Process where Name="xyz.exe"' )
pid = p[0].Properties_('P rocessId').Valu e
return pid[/CODE]
Any ideas?
Thanks,
aRuN
Given below is the function i have defined to find process id of the running process xyz.exe. But when i try to run this function when the process xyz.exe is not running, obviously "pid = p[0].Properties_('P rocessId').Valu e" shows error as the process doesn't exist.
but i want it to return pid="" ,to use that value to check if the process is running or not.I am now managing with a try block to catch the exception and return pid="".but this looks bit awkward.
So would like some experts to pitch in with some idea to implement something more elegant.
[CODE=python]from win32com.client import GetObject
WMI = GetObject('winm gmts:')
def getPid():
pid = ""
p=None
processes = WMI.InstancesOf ('Win32_Process ')
p = WMI.ExecQuery(' select * from Win32_Process where Name="xyz.exe"' )
pid = p[0].Properties_('P rocessId').Valu e
return pid[/CODE]
Any ideas?
Thanks,
aRuN
Comment