Possible Duplicate:
Vbscript – Read ini or text file for specific section
I am trying to check whether IPaddress of other PC can be accessed or not.
If IPaddress is static, following code is ok.
vbscript code
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
As I want to check dynamic IPaddress, use ini file.
ini file
[IPaddress]
IP001 = "192.168.10.1";
IP002 = "192.168.10.2";
Now, I would like to know how to connect ini file and vbscript code.
Please explain it to me.
As Shadow Wizard mentions in his comment, you’ll need to use FSO (FileSystemObject) to read the file. The sample code for OpenTextFile would probably be a good place to begin.
If you move your current vbscript code into a Sub that accepts one ip address as the argument you can just call that sub for each ip address in the file.
Maybe something like this (completely untested code):
The code that gets out the
ipAddressfrom thelineprobably needs to be rewritten to be a bit more flexible though. And if the ini file contains a lot of other data maybe you need to add some code to skip to the correct section etc.