Jan 2, 2007 - How Can I Append a Blank Line to a Text File, Then Append the Current. We then call the Write method, appending the value of the VBScript.
'This script was adapted by Adam Lawson 'This will add a line into a file useful if you deploy printers from C: drive or network drives 'on a PC basis set objWS = CreateObject ( 'Wscript.Shell' ) Set fsob = CreateObject ( 'Scripting.FileSystemObject' ) strNewLine = 'INSERT LINE TO ADD EG. Net use H: server share' strFileName = 'INSERT THE FILE PATH HERE EG. C: networkdrives.bat' Const FORREADING = 1 Const FORWRITING = 2 strCheckForString = UCase ( 'NEW LINE WILL BE INSERTED AFTER THIS TEXT EG. @echo off' ) Set objFS = CreateObject ( 'Scripting.FileSystemObject' ) Set objTS = objFS. OpenTextFile ( strFileName, FORREADING ) strContents = objTS. ReadAll objTS. Close arrLines = Split ( strContents, vbNewLine ) Set objTS = objFS.
OpenTextFile ( strFileName, FORWRITING ) For Each strLine In arrLines If ( Left ( UCase ( LTrim ( strLine )), Len ( strCheckForString )) = strCheckForString ) Then objTS. WriteLine strLine objTS. WriteLine strNewLine else objTS. WriteLine strLine End If 'IF YOU RUN FROM GROUP POLICY YOU CAN RUN AN 'IF EXIST' AND CHECK FOR THE FOLLOWING OUTPUT FILE 'SO IT WILL NOT RUN AGAIN. IF YOU WANT THIS OPTION REMOVE THE ' 'Next 'Set objFSO = CreateObject('Scripting.FileSystemObject') 'Set objFile = objFSO.CreateTextFile('C: REPROPRT.txt').
![Vbs Vbs](https://cdn.guru99.com/images/7-2015/071715_0510_ReadingandW1.png)
VBScript has no built-in functionality that lets you insert a line into a file. The simplest way to do that is to open the file you want to insert a line into, write the file line by line to a new file, and insert the new line where you want it. I wrote the following script, which you can download at, to insert a line into a sysprep.inf file in the Unattended section.