Vizible’s Blog

Python – Find process by Name / Title

Posted in Programming, Python by wearetherock on August 3, 2009

With this example, getProcesssByName not usable for SetForegroundWindow & ShowWindow

	def getProcessByName(self, name) :
		from win32com.client import GetObject
		WMI = GetObject('winmgmts:')
		processes = WMI.ExecQuery('select * from Win32_Process where Name="%s"' % (name))
		if len(processes) == 0 :
			print "%s is not running ..." % (name)
			return 0
		else :
			handle = processes[0].Properties_('Handle').Value
			return handle

	def getProcessByTitle(self, title ):
		hwnd = win32gui.FindWindowEx(0,0,0, title)
		return hwnd

	def showXBMC(self):
		hwnd = self.getProcessByTitle("XBMC Media Center")

	def hiddenXBMC(self):
		handler = self.getProcessByTitle("XBMC Media Center")
		print "xbmc handle = ", handler
		isWork = win32gui.ShowWindow(handler, win32con.SW_HIDE)
		print "is work =", bool(isWork)



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: