/build/static/layout/Breadcrumb_cap_w.png

Scripting Question


Need a script to edit multiple ini files

04/06/2015 2032 views

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

0 Comments   [ + ] Show comments

Comments



Community Chosen Answer

2
you should be able to take this script and modify it for your use

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

Answered 04/06/2015 by: SMal.tmcc
Red Belt

All Answers

0

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.

Answered 04/07/2015 by: VBScab
Red Belt

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ