-1
我是vbscript的新手。我試圖從下面的PingTest函數獲取返回值,但它在函數定義中給我一個錯誤(我正在使用Windows 10)。使用VBScript從函數返回值
Function PingTest(hostName)
' Standard housekeeping
Dim colPingResults, objPingResult, strQuery
' Define the WMI query
strQuery = "SELECT * FROM Win32_PingStatus WHERE Address = '" & hostName & "'"
' Run the WMI query
colPingResults = GetObject("winmgmts://./root/cimv2").ExecQuery(strQuery)
' Translate the query results to either True or False
For Each objPingResult In colPingResults
If Not IsObject(objPingResult) Then
PingTest = False
ElseIf objPingResult.StatusCode = 0 Then
PingTest = True
Else
PingTest = False
End If
Next
colPingResults = Nothing
End Function
Dim output
output= PingTest("www.google.com")
WScript.Echo output
你說錯了?哪一個? – JNevill
它說「Line1:Char 31 Expected statement」 –
修改後的代碼有效! –