0

如果这是重复,我深表歉意,但到目前为止我没有找到合适的帮助。

我想要完成的是列出具有特定值的计算机的所有网络适配器(WMI 中的 NetConnectionStatus 中的 2)。然后,从这个网络适配器名称列表中,我想检查其中一些是否包含一个字符串,而不包含另一个。

在我的示例中,如果字符串包含“Juniper”,我不想评估该字符串。但是,如果字符串包含例如“4G”或“HSPA”或“Mobile”,我想回显“Mobile”,否则“Not Mobile”

所以基本上这是我的第一次尝试(但这给了我一个无限循环......)

非常感谢你的帮助 !

Set oWsh = WScript.CreateObject("WScript.Shell")   

Set oWshSysEnv = oWsh.Environment("PROCESS")   

Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")   

Set colItems = GetObject("WinMgmts:root/cimv2").ExecQuery("select Name from Win32_NetworkAdapter where (NetConnectionStatus = 2)")   

Dim commentStr

For Each objItem In colItems      

commentStr = ObjItem.Name

Do While not InStr(1, commentStr, "Juniper") > 0

If InStr(1, commentStr, "4G") > 0 then

wscript.echo "Mobile"

Else

wscript.echo "Not Mobile"

End If

Loop

Next
4

1 回答 1

0

正如@lankymart 所建议的那样,我终于设法使用各种 If 得到了我想要的东西:

Set oWsh = WScript.CreateObject("WScript.Shell")   

Set oWshSysEnv = oWsh.Environment("PROCESS")   

Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")   

Set colItems = GetObject("WinMgmts:root/cimv2").ExecQuery("select Name from Win32_NetworkAdapter where (NetConnectionStatus = 2)")   



Dim commentStr

Dim mobile

Dim Juniper



For Each objItem In colItems      

commentStr = ObjItem.Name



If InStr(1, commentStr, "Juniper") > 0 then

Juniper=1

End If

If InStr(1, commentStr, "Mobile") > 0 then

Mobile=1

End If

If InStr(1, commentStr, "HSPA") > 0 then

Mobile=1

End If


Next


If Juniper=1 And Mobile=1 then

wscript.echo "Mobile"

Else

wscript.echo "Not Mobile"

End If
于 2020-02-28T15:54:03.040 回答