I am writing a little app that opens up a logon script using a StreamReader and populates various controls such as text boxes and check boxes etc based on the values in the script. I can get it to read properly and all is wonderful with it thus far.
The problem comes when I want to save the bloody thing. I need to be able to write a value into the script in the same location that is in and I don't want to rewrite the ~ENTIRE~ script as well.
I know one option would be to place the entire contents of the script into a vaiable, replace the text in question with new text then create a new file overwritting the old etc. I don't want to do that if I can avoid it (Though I am exploring this path as well).
What I was doing is reading in the script again, line by line. When I get to a line that I know ~could~ be modified I check to see if it was changed through the UI and if it was, I want to overwrite the line with the new text. Below is a sample of what I have thus far in code, but the text is getting written in the wrong location in my script, a sample of the script is further below. What I was hoping I could somehow do is if I am reading a specific line, I want the writer to write directly to it, replacing the current text. It seems that I should be using something other than a StreamReader and StreamWriter but I can't think of anything else. I appreciate all the help in advance!
Dim FS As FileStream = New FileStream(tScriptName.Tex
t, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)
Using StreamReader As StreamReader = New StreamReader(FS)
Dim sLine As String
Do
sLine = StreamReader.ReadLine
If sLine.Contains("aSN = Array(") = True Then
If bServerName = True Then ' Name Change Only
Dim snTemp As String = " aSN = Array(" & String.Join(",", SNArray) & ")"
Using SW As StreamWriter = New StreamWriter(FS)
SW.WriteLine(snTemp)
End Using
End If
ElseIf sLine.Contains("' End") Then
Beep()
End If
Loop Until sLine = "' End"
End Using
FS.Close()
Here is also a sample of the logon script:
aOU = Array("ou=torrance", "ou=irvine")
aSN = Array("\\CLS3", "\\irvinesvr\")
sDS = "developer6" ' Share Name
' Commands
Call AdminPwd()
Call MapDrives()
Call LogonScripts()
Call CheckNAV()
Start Free Trial