'DimQQUIN
SetobjWMIService=GetObject_
("winmgmts:"&"."&"rootcimv2")
Setps=objWMIService.ExecQuery_
("SELECT*FROMWin32_process")
ForEachpsinps'列出系统中所有正在运行的程序
'foreachpsingetobject("winmgmts:.rootcimv2:win32_process").instances_'列出系统中所有正在运行的程序
IfLCase(ps.Name)="qq.exe"OrLCase(ps.Name)="tm.exe"Then'检测是否QQ或TM
AppPath=ps.commandline'提取QQ程序的命行
tmp=Replace(AppPath,Chr(34),Space(1))
UIN1=InStr(tmp,"QQUIN:")+6
QQUIN=Mid(tmp,UIN1,InStr(UIN1,tmp,Space(1))-UIN1)'取QQ号码.
EndIf
Next
IfLen(QQUIN)=0Then
MsgBox"系统中没有运行QQ或TM程序,请重新启动QQ或TM,登陆后再使用一键换切换一下QQ或TM程序,再运行本脚本"
Else
Do'循环检测
myqqin=chkuin(QQUIN)'检测上面提取出来的QQ号码是否有在本机打开
IfNotmyqqinThen'如果没有运行则,重新运行QQ程序并登录
runapp(AppPath)'
wscript.sleep10000'等待10秒
Else
wscript.sleep5000'等待5秒
EndIf
Loop'返回继续检测
EndIf
FunctionRunApp(AppPath)
Dimobj
Setobj=CreateObject("WScript.Shell")
obj.exec(AppPath)
EndFunction
Functionchkuin(QQUIN)
SetobjWMIService=GetObject_
("winmgmts:"&"."&"rootcimv2")
Setps=objWMIService.ExecQuery_
("SELECT*FROMWin32_process")
ForEachpsinps'列出系统中所有正在运行的程序
'foreachpsingetobject("winmgmts:.rootcimv2:win32_process").instances_
IfLCase(ps.Name)="qq.exe"OrLCase(ps.Name)="tm.exe"Then
AppPatht=ps.commandline
'bychenallqq368178720
tmp=Replace(AppPatht,Chr(34),Space(1))
UIN1=InStr(tmp,"QQUIN:")+6
QQUINTMP=Mid(tmp,UIN1,InStr(UIN1,tmp,Space(1))-UIN1)
IfQQUINTMP=QQUINThenchkuin=TrueEndIf
EndIf
Next
EndFunction