場景是通過深信服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
uj5u.com熱心網友回復:
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!"
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/26855.html
標籤:VBA
上一篇:Excel vba的時候一直抱運行時錯誤‘1004’,如何修改,ActiveSheet.Shapes(picture_name).Select這句之后出錯的
下一篇:vba
