johnmoore83
Technical User
Hi I have loads of logon scripts which point to drives which aren't available any more.
So I need a VBScript which goes through each .vbs logon script and deletes a particular line.
I have created a text file c:\names.txt which points to where the .VBS logon files are located. so in the txt file it has
c:\new\personsname1.vbs
c:\new\personsname2.vbs
The script I have developed so far deletes all the contents of the last vbs script and doesn't delete the info in the first one.
-----------------------------------------------------------------
Const ForReading = 1 ' Open file read only
Const ForWriting = 2 ' Open file read write
Set objDictionary = CreateObject("Scripting.Dictionary") ' Creates an array
' Variables
Dim objFso, objFile, strFileName, strNextLine, StrTextall, strLine, strNewContents
'----------------------------------------------------------------
' Specify text file path and assigns it to the variable strfilename
strFileName = "c:\names.txt"
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(strFileName, 1)
i = 0
' If text file exists then do this
If objFSO.FileExists(strFileName) Then
' Reads each line of c:\names.txt and stores each line as strNextLine
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
objDictionary.Add i, strNextLine
i = i + 1
' Stores each line in objdicionary as strnextline
WScript.Echo("File Location: " & StrNextLine)
Loop
'Opens the vbs script file and reads all contents and stores it as strTextall
Set objFile = objFspenTextFile(strNextLine, ForReading)
StrTextall = ObjFile.ReadAll
' Searches vbs file for text
Do Until objFile.AtEndOfStream
strNextLine = objFile.ReadLine
If InStr(strLine, "\\tasrv") = 0 and InStr(strLine, "\\erp_srv") = 0 Then
strNewContents = Replace(StrNextLine, "\\tasrv", "blank")
strNewContents = Replace(StrNextLine, "\\erp_srv", "blank")
End If
Loop
' Write out file
Set ObjFile = objFSO.OpenTextFile(strNextLine, ForWriting)
objFile.WriteLine strNewContents ' Write out the string contents
objFile.Close ' close the file
objFile.Close ' close the file
Else
'catch exceptions how you please
MsgBox "The ini file: " & strFileName & " does not exist. No changes will be made."
End If
So I need a VBScript which goes through each .vbs logon script and deletes a particular line.
I have created a text file c:\names.txt which points to where the .VBS logon files are located. so in the txt file it has
c:\new\personsname1.vbs
c:\new\personsname2.vbs
The script I have developed so far deletes all the contents of the last vbs script and doesn't delete the info in the first one.
-----------------------------------------------------------------
Const ForReading = 1 ' Open file read only
Const ForWriting = 2 ' Open file read write
Set objDictionary = CreateObject("Scripting.Dictionary") ' Creates an array
' Variables
Dim objFso, objFile, strFileName, strNextLine, StrTextall, strLine, strNewContents
'----------------------------------------------------------------
' Specify text file path and assigns it to the variable strfilename
strFileName = "c:\names.txt"
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(strFileName, 1)
i = 0
' If text file exists then do this
If objFSO.FileExists(strFileName) Then
' Reads each line of c:\names.txt and stores each line as strNextLine
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
objDictionary.Add i, strNextLine
i = i + 1
' Stores each line in objdicionary as strnextline
WScript.Echo("File Location: " & StrNextLine)
Loop
'Opens the vbs script file and reads all contents and stores it as strTextall
Set objFile = objFspenTextFile(strNextLine, ForReading)
StrTextall = ObjFile.ReadAll
' Searches vbs file for text
Do Until objFile.AtEndOfStream
strNextLine = objFile.ReadLine
If InStr(strLine, "\\tasrv") = 0 and InStr(strLine, "\\erp_srv") = 0 Then
strNewContents = Replace(StrNextLine, "\\tasrv", "blank")
strNewContents = Replace(StrNextLine, "\\erp_srv", "blank")
End If
Loop
' Write out file
Set ObjFile = objFSO.OpenTextFile(strNextLine, ForWriting)
objFile.WriteLine strNewContents ' Write out the string contents
objFile.Close ' close the file
objFile.Close ' close the file
Else
'catch exceptions how you please
MsgBox "The ini file: " & strFileName & " does not exist. No changes will be made."
End If