求助 如何在现有基础上 通过vb脚本实现需求

linivy1987 2019-07-29 07:50:28

场景是通过深信服sslvpn拨号登陆后,启动华为云桌面客户端,但是因为流程上有两个客户端 领导操作上不方便

本人小白一枚,想借宝地一问各位大拿,如何在现有代码基础上实现如下需求,请不吝赐教

1. 启动sslvpn客户端 (进程为a.exe)

2. 启动华为客户端 (进程为b.exe)

3. 当检测到进程c.exe运行了,结束b.exe

4. 当检测到进程c.exe结束了,结束a.exe

整个过程如上,目前代码实现了1和2两个步骤。。。


dim wsh
set wsh=Wscript.createobject("wscript.shell")

wsh.exec "C:\Program Files (x86)\Sangfor\SSL\SangforCSClient\SangforCSClient.exe"


'执行ping检测
succCount=0

'尝试检查网络连通情况的次数
retrytimes=500

'当有一次能ping通则认为网络是通的
While succCount < 1 and retrytimes > 0
set objwmi=GetObject("winmgmts:\\.\root\cimv2")
set objitems=objwmi.ExecQuery("select * from Win32_PingStatus where Address='192.168.1.100'")
for each objitem in objitems
if objitem.statuscode = 0 then
succCount=succCount+1
end if
'wscript.sleep(30)
retrytimes=retrytimes-1
next
wend

if succCount>0 then
wsh.exec "C:\Program Files (x86)\Huawei\HDPClient\CloudClient.exe"
else
wscript.echo "打开桌面客户端失败!"
end if

...全文
36 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
milaoshu1020 2019-07-30
  • 打赏
  • 举报
回复

Set objwmi = getobject("winmgmts:\\.\root\cimv2")
Set shell = createobject("wscript.shell")

shell.exec "notepad.exe" ' A.EXE
shell.exec "mspaint.exe" ' B.EXE

Do
Set colitems = objwmi.execquery("select * from win32_process where name='cmd.exe'") ' C.EXE
If colitems.count > 0 Then
Set colitems = objwmi.execquery("select * from win32_process where name='notepad.exe'")
For Each objitem In colitems
objitem.terminate()
Next
Exit Do
End If
wscript.sleep 500
Loop

Do
Set colitems = objwmi.execquery("select * from win32_process where name='cmd.exe'")
If colitems.count = 0 Then
Set colitems = objwmi.execquery("select * from win32_process where name='mspaint.exe'")
For Each objitem In colitems
objitem.terminate()
Next
Exit Do
End If
wscript.sleep 500
Loop

msgbox "done!"

2,462

社区成员

发帖
与我相关
我的任务
社区描述
VBA(Visual Basic for Applications)是Visual Basic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。
社区管理员
  • VBA
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧