- '''
- 通过访问http://wpa.qq.com/pa?p=1:QQ号码:1查询返回的图片
- 如果返回 2329 则在线 2262 则离线
- '''
- import os,time,datetime,string
- import urllib2
- def chk_qq(qqnum):
- chkurl = 'http://wpa.qq.com/pa?p=1:'+`qqnum`+':1'
- a = urllib2.urlopen(chkurl)
- length=a.headers.get("content-length")
- a.close()
- #print length
- print datetime.datetime.now()
- if length=='2329':
- return 'on'
- elif length=='2262':
- return 'off'
- else:
- return 'Unknown Status!'
- #循环判断输入qq号码是否在线
- '''while True:
- qq = raw_input("input the QQ num:")
- if ( qq != "q" ):
- qq = string.atoi(qq)
- stat = chk_qq(qq)
- print `qq` + ' is ' + stat + '\\n'
- else:
- print "exit!!"
- exit(0)
- '''
- #进程检测
- #-*- coding:utf-8 -*-
- def check_exsit(process_name):
- import win32com.client
- WMI = win32com.client.GetObject('winmgmts:')
- processCodeCov = WMI.ExecQuery('select * from Win32_Process where Name="%s"' % process_name)
- if len(processCodeCov) > 0:
- #print '%s is exists' % process_name
- return 0
- else:
- #print '%s is not exists' % process_name
- return 1
- pro_name = "TTPlayer.exe"
- while True:
- qq = 403054983
- stat = chk_qq(qq)
- if ( stat == "on" ): #在线-启动
- print "启动%s成功"%pro_name
- os.popen(r'"D:\\Program Files\\TTPlayer\\TTPlayer.exe"')
- print "xxxxxxx"
- elif ( stat == "off" ): #离线-关闭
- status = check_exsit(pro_name) #关闭前判断状态
- #print status
- if ( status == 0 ):
- os.system("taskkill /f /im TTPlayer.exe")
- print "kill %s is OK!"% pro_name
- elif ( status == 1 ):
- print "this %s don't exists!" % pro_name
- time.sleep(5)
- #该片段来自于http://www.codesnippet.cn/detail/030620133752.html
来源: http://www.codesnippet.cn/detail/030620133752.html