帮忙写个VBS脚本,谢谢

2024年11月30日 03:25
有5个网友回答
网友(1):

PingHost "192.168.1.1"
Sub PingHost(sHost)
Set oWsh = CreateObject("WScript.Shell")
oWsh.Run "cmd"
oWsh.AppActivate "C:\WINDOWS\system32\cmd.exe"
oWsh.SendKeys "ping "&sHost&" -w 1000 >C:\ping.log~"
WScript.Sleep 15000
oWsh.AppActivate "C:\WINDOWS\system32\cmd.exe"
oWsh.SendKeys "exit~"
Set oFso = CreateObject("Scripting.FileSystemObject")
Set oFile = oFso.OpenTextFile("C:\ping.log",1,False)
s = Trim(oFile.ReadAll)
iStart = InStr(s,"Received = ")+11
num = Mid(s,iStart,1)
If num="0" Then
WScript.Quit
End If
End Sub

网友(2):

非常批处理的 孤星 ???

VBS检测网络没有批处理灵活
可以用批处理检测后,把结果做为参数 给vbs判断
这样相对更简洁一点。

把下面代码保存为 bat文件运行 [核心还是 VBS]

'& if not "%~1"=="smile" start /min cmd /c "%~F0" smile& exit
'wind_smile& ping /n 1 192.168.0.2>nul&& set wind=wind|| set wind=smile
'& start wscript /e:vbs "%~F0" %wind%& exit

if wscript.arguments(0) = "wind" then
msgbox "这里执行ping通的语句"
else
msgbox "这里执行不通的语句"
end if

网友(3):

Dim WebAddress
WebAddress=InputBox("请输入你要ping的网络地址","ping a computer without using ping.exe","www.google.cn")
If WebAddress <> "" Then
Set OBJWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colPings = OBJWMIService.ExecQuery("Select * From Win32_PingStatus Where Address = '" &WebAddress& "'")
For Each OBJStatus in colPings
If IsNull(OBJStatus.StatusCode) Or OBJStatus.StatusCode <> 0 Then
WScript.Echo "网址:" & WebAddress & "无法连接,程序将退出!"
Else
call Main
End If
Next
End If

function Main()
WScript.Echo "网址已成功连接,你可以的此处增加相关代码!"
end function

网友(4):

孤星?
用WMI,不过忘了,下次再说吧

网友(5):

能难住孤星的批处理一定没那么简单啊。~~

大家还是仔细回答吧。