|
本帖最后由 9zhmke 于 2021-8-17 14:18 编辑
我写了个配合的VBS,一起测试下,运行后先打开网络中带有VMware字样的网卡,再调用VM执行程序,直到退出后再关闭VM的网卡
- dim proce,cmd,txt
- call NIC_ENABLED(1)'开VM网卡
- WScript.CreateObject("WScript.Shell").Run "vmware.exe"
- do
- wscript.sleep 3000'每三秒检测一次VM是否在运行
- For each cmd in getobject("winmgmts:\\.\root\cimv2").execquery("select * from win32_process")
- if lcase(cmd.name)="vmware.exe" then exit do
- next
- loop
- wscript.sleep 5000
- call NIC_ENABLED(0)'关VM网卡并退出
- Function NIC_ENABLED(key)'启用VM虚拟机网卡
- txt=" admin=DISABLED":if key=1 then txt=" admin=ENABLED"'启禁用网卡参数
- For Each proce In GetObject("Winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2").ExecQuery("SELECT * FROM Win32_NetworkAdapter ")
- if instr(proce.NetConnectionID,"VMware")>0 then
- cmd="""" & proce.NetConnectionID & """" & txt
- WScript.CreateObject("WScript.Shell").Run """netsh.exe""" & " interface set interface name=" & cmd ,0
- end if
- Next
- End Function
复制代码 |
|