1
可能重複:
Vbscript - Read ini or text file for specific section如何使用VBScript讀取ini文件?
我想檢查其他計算機的名稱IP地址是否可以訪問或沒有。 如果IP地址是靜態的,則下面的代碼是可以的。
VBScript代碼
Dim Shell, strCommand, strHost, ReturnCode
strHost = "192.168.10.1"
Set Shell = wscript.createObject("wscript.shell")
strCommand = "ping -n 1 -w 300 " & strHost
ReturnCode = Shell.Run(strCommand, 0, True)
If ReturnCode = 0 Then
wscript.echo strHost & " is pingable"
Else
wscript.echo strHost & " is not pingable"
End If
當我想檢查動態名稱IP地址,使用INI文件。
ini文件現在
[IPaddress]
IP001 = "192.168.10.1";
IP002 = "192.168.10.2";
,我想知道如何連接ini文件和VBScript代碼。 請給我解釋一下。
VBScript中沒有內置功能 - 唯一的方法是使用普通FSO並解析記錄你自己。 –
這是一個有用的項目:[INI Reader/Writer Class](http://www.codeproject.com/KB/files/VB_NET_INIFile_Object.aspx) –
檢查[這個答案](http://stackoverflow.com/questions/ 3491965/vbscript-read-ini-or-text-file-for-specific-section/7469754#7469754)它應該能夠處理你所需要的,並且非常靈活,如果你在INI文件中有更改,將來會更好。 。 –