ChickenMan81
MIS
Trying to create the following script and keep getting a Bad File Mode error. Can someone help me. I'm not much of a programmer and I'm banging my head against the wall. The error is on the line that reads:
Do Until ipFileObj.AtEndOfStream = True
In order to run the script you have to create a file called IP_Addresses.csv. Thank you for any help!
' Defining constants
const READ = 1
const WRITE = 2
const APPEND = 8
const ASCII = 0
' Defining variables and initializing
dim fileName, ipAddrStr, newRoom, comp1_IP, comp2_IP, comp3_IP, comp4_IP
fileName = "IP_Addresses.csv"
ipAddrStr = ""
newRoom = "106"
comp1_IP = "192.168.10.59"
comp2_IP = "192.168.10.60"
comp3_IP = "192.168.10.61"
comp4_IP = "192.168.10.62"
' Creating ASCII text file and overwriting
Set fso = CreateObject("Scripting.FileSystemObject")
ipAddrStr = _
newRoom & ",1," & comp1_IP & vbCrLf & _
newRoom & ",2," & comp2_IP & vbCrLf & _
newRoom & ",3," & comp3_IP & vbCrLf & _
newRoom & ",4," & comp4_IP & vbCrLf
'Append New Room Information to File
Set fso = CreateObject("Scripting.FileSystemObject")
If NOT fso.FileExists(fileName) Then
WScript.StdOut.WriteLine(Chr(7) & Chr(7)),0, False
WScript.StdOut.WriteLine("File Does Not Exit!!!" & vbCrlf & _
"You Must Create the File Before You can Read the File!!")
WScript.Quit
End If
Set ipFileObj = fspenTextFile(fileName,APPEND,ASCII)
ipFileObj.Write(ipAddrStr)
ipFileObj.Close()
' Read and write IPs file
Set ipFileObj = fspenTextFile(fileName,APPEND,ASCII)
' Read file one line at a time displaying room, computer, and IP
Do Until ipFileObj.AtEndOfStream = True
room = ipFileObj.Read(3)
ipFileObj.Skip(1)
computer = ipFileObj.Read(1)
ipFileObj.Skip(1)
ipAddress = ipFileObj.Read(13)
ipFileObj.SkipLine()
WScript.Echo "The IP Address in Room "& room &" for Computer " & computer& " is " &ipAddress
Loop
ipFileObj.Close()
Do Until ipFileObj.AtEndOfStream = True
In order to run the script you have to create a file called IP_Addresses.csv. Thank you for any help!
' Defining constants
const READ = 1
const WRITE = 2
const APPEND = 8
const ASCII = 0
' Defining variables and initializing
dim fileName, ipAddrStr, newRoom, comp1_IP, comp2_IP, comp3_IP, comp4_IP
fileName = "IP_Addresses.csv"
ipAddrStr = ""
newRoom = "106"
comp1_IP = "192.168.10.59"
comp2_IP = "192.168.10.60"
comp3_IP = "192.168.10.61"
comp4_IP = "192.168.10.62"
' Creating ASCII text file and overwriting
Set fso = CreateObject("Scripting.FileSystemObject")
ipAddrStr = _
newRoom & ",1," & comp1_IP & vbCrLf & _
newRoom & ",2," & comp2_IP & vbCrLf & _
newRoom & ",3," & comp3_IP & vbCrLf & _
newRoom & ",4," & comp4_IP & vbCrLf
'Append New Room Information to File
Set fso = CreateObject("Scripting.FileSystemObject")
If NOT fso.FileExists(fileName) Then
WScript.StdOut.WriteLine(Chr(7) & Chr(7)),0, False
WScript.StdOut.WriteLine("File Does Not Exit!!!" & vbCrlf & _
"You Must Create the File Before You can Read the File!!")
WScript.Quit
End If
Set ipFileObj = fspenTextFile(fileName,APPEND,ASCII)
ipFileObj.Write(ipAddrStr)
ipFileObj.Close()
' Read and write IPs file
Set ipFileObj = fspenTextFile(fileName,APPEND,ASCII)
' Read file one line at a time displaying room, computer, and IP
Do Until ipFileObj.AtEndOfStream = True
room = ipFileObj.Read(3)
ipFileObj.Skip(1)
computer = ipFileObj.Read(1)
ipFileObj.Skip(1)
ipAddress = ipFileObj.Read(13)
ipFileObj.SkipLine()
WScript.Echo "The IP Address in Room "& room &" for Computer " & computer& " is " &ipAddress
Loop
ipFileObj.Close()