Need a script to edit multiple ini files
I wanted to find out if you can help me with a script that will edit .ini files, and update the server name. We have about 1700 ini files. That need to have new print server names since the old server is are going to be decommissioned soon.
The filed that needs to be updated is the Host value. Ie if the Host value is Host = “KBFILE01” it should be update to Host = “vKBprt01”
** The problem that I am having is that instead of the script replace the value in Host it is replacing the whole line.
Before Script:
Printer=SMB2 Local Name="Windows Printer | LB-28-11" Host="KBFILE01" Name="LB-28-11" PrinterID="HP LaserJet 4100 Series PCL6" Class="PCL5" Enabled=yes
After I run the script below:
Host="vKBprt01"
I need it to be like :
Printer=SMB2 Local Name="Windows Printer | LB-28-11" Host="vKBprt01" Name="LB-28-11" PrinterID="HP LaserJet 4100 Series PCL6" Class="PCL5" Enabled=yes
Thanks
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("C:\Tests.ini", ForReading)
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
intLineFinder = InStr(strNextLine, Host="LBPRINT01")
If intLineFinder <> 0 Then
strNextLine = "Host= vLBprt02"
End If
strNewFile = strNewFile & strNextLine & vbCrLf
Loop
objTextFile.Close
Set objTextFile = objFSO.OpenTextFile("C:\Tests.ini", ForWriting)
objTextFile.WriteLine strNewFile
objTextFile.Close
Answers (2)
http://www.itninja.com/question/number-of-autologins-required-has-changed-from-1-to-3-since-3-6-upgrade
fixlogin.vbs:
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("c:\windows\panther\unattend.xml", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, "LogonCount>1</LogonCount",
"LogonCount>3</LogonCount")
Set objFile = objFSO.OpenTextFile("c:\windows\panther\unattend.xml", ForWriting)
objFile.WriteLine strNewText
objFile.Close
There's quite a good INI class here. It does most of what you'd need to manipulate INIs.
Don't be put off by the word 'class' - it's just a bunch of functions and property gets/sets.