我需要一个命令来显示vbs中执行cmd参数的结果。我把代码作为
<script language="VBScript" type="text/vbscript">
set objShell = CreateObject("WScript.Shell")
strOut=""
sub start
cmdarg="%comspec% /c netsh wlan show hosted "
set objExCmd = objShell.Exec(cmdarg)
strOut=objExCmd.StdOut.ReadAll
Set regEx = New RegExp
regEx.Pattern = "[\f\n\r\v]+"
regEx.Global = True
regEx.Multiline = True
strOut = regEx.Replace(strOut, "<br>")
TraceOut.innerHTML= strOut
end sub
</script>
此列表执行后的所有输出如下:
Mode : Allowed
SSID name : "MyWiFi"
Max number of clients : 10
Authentication : WPA2-Personal
Cipher : CCMP
Status : Not started
我只需要显示SSID名称。即,“MyWiFi” 每当我更改ssid名称时它都会改变。所以它并不总是“MyWiFi”
这是完整的HTA计划
<head><title>Hosted Network</title>
<HTA:APPLICATION ID="oHTA";
APPLICATIONNAME="Hosted Network";
BORDER="thin";
BORDERSTYLE="normal";
SINGLEINSTANCE="no";
>
</head><body bgcolor="#E8E8E8" >
<script language="VBScript" type="text/vbscript">
sub subfn
set objShell = CreateObject("WScript.Shell")
cmdarg="%comspec% /c netsh wlan show hosted"
set strOut = objShell.Exec(cmdarg)
Dim re : Set re = New RegExp
re.Multiline = True
re.Pattern = "^SSID\s+name\s+:\s+""([^""]+)"""
strOut = "SSID: >" & re.Execute(strOut)(0).Submatches(0) & "<"
TraceOut.innerHTML= strOut
end sub
</script>
<input type="Button" name="B1" value="Find" onclick="subfn">
<div id=TraceOut></div></body>
</html>
答案 0 :(得分:1)
使用带有捕获/组/子匹配的RegExp从netsh输出中剪切所需的信息:
Dim strOut : strOut = Join(Array( _
"Mode : Allowed" _
, "SSID name : ""MyWiFi""" _
, "Max number of clients : 10" _
), vbCrLf)
WScript.Echo strOut
Dim re : Set re = New RegExp
re.Multiline = True
re.Pattern = "^SSID\s+name\s+:\s+""([^""]+)"""
WScript.Echo "SSID: >" & re.Execute(strOut)(0).Submatches(0) & "<"
输出:
Mode : Allowed
SSID name : "MyWiFi"
Max number of clients : 10
SSID: >MyWiFi<
(但我不知道'排序'是如何成为问题的一部分)