Re: Replace string in .inf file

From: Bernard Dejonckheere (no.bdejonckheere.spam_at_no.hotmail.com.spam)
Date: 03/07/04


Date: Sun, 7 Mar 2004 12:48:46 +0100

I had the same problem once,
the thing I do now is in cmd-prompt:
type original.inf > work.inf
and do my operations on that one

Bernard
-----------------------------------------------------------
"Maxence" <arkoven(supprimez-ceci)@hotmail.com> wrote in message
news:#6NZ7RwAEHA.3804@TK2MSFTNGP09.phx.gbl...
Hi,

I would to replace one string by another string an .inf file which was
create by Windows.
I have a script which works with all my test files (txt, inf) but it's don't
work with the original .inf file. All strings are replace by??????
characters.
Probably a problem with unicode text because all .inf files begin with :
"
[Unicode]
Unicode=yes
[Version]
signature="$CHICAGO$"
Revision=1
"
By exemple, I use the secsetup.inf in c:\Windows\repair folder (XP Pro
station)

I don't know how I can bypass the unicode text in my script and especially
that this file, after replace string, can always be used by Windows. II
have tried to use unicode option to create my temp File... but no success

Someone has an idea ?

Thanks @ lot !!!

Maxence

This is my script... Maybe someone will be interested... you can use with
all files but be careful don't use with really unicode file otherwise you
break it ;-)

'=================================================

Dim Shell
Dim System
Set Shell = CreateObject("Wscript.Shell")
Set System = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
Const ForWriting = 2

'Path of the .inf File
PathFile = "C:\Temp\MyFile.inf"

'Old Text
OldTxt = "oldvalue"

'New Text
NewText = "newvalue"

ChangeText PathFile, oldTxt, NewText

'-----------------------------------------
'Sub ChangeText
'-----------------------------------------

Sub ChangeText(FileINF, MyText, NewText)

 Dim ThisFile
 Set ThisFile = System.OpenTextFile(FileINF,ForReading)
 countx=0

 While Not ThisFile.AtEndOfStream
   strFile = strFile & ThisFile.ReadLine & vbcrlf
 Wend
 ThisFile.Close
 Do until instr(strFile, MyText) = False
   countx= countx + 1
   strFile = Replace(strFile, MyText, NewText,1,1)
 Loop

 TempFile strFile, FileINF

 MsgBox MyText & " was found and replaced with " & newtext & " " & countx &
" times.", , "Toms cool text replace script"

End Sub

'------------------------------
'Sub TempFile
'function that writes results to the temp file and move it insteed old file
'------------------------------

Sub TempFile( newString,FileINF )
  myfile = FileINF
  Set fso = CreateObject("Scripting.FileSystemObject")
  OutFile = "C:\#temp#.txt"
  set textstream = fso.OpenTextFile(myFile,1,true)
  Set OutStream=fso.CreateTextFile(OutFile,True)
  OutStream.WriteLine( newstring)
  textstream.close
  OutStream.Close
  fso.CopyFile OutFile, myfile, true
  fso.DeleteFile OutFile
End Sub



Relevant Pages

  • Replace string in .inf file
    ... I would to replace one string by another string an .inf file which was create by Windows. ... I have a script which works with all my test files but it's don't work with the original .inf file. ... Probably a problem with unicode text because all .inf files begin with: ... Sub ChangeText ...
    (microsoft.public.scripting.vbscript)
  • Re: Detecting is hyperthreading is enabled with WMI?
    ... It is too bad that WMI does not give this info. ... have to be done to the script. ... Public Sub DisplayProcessorInfo ... dim ProcessorSet, Processor ...
    (microsoft.public.windowsxp.wmi)
  • Cant make this page work
    ... I can't make this script work properly. ... The script at the bottom of the html page ... Does someone have a perl ... sub output_trace_headers { ...
    (comp.lang.javascript)
  • Re: Win32_Product doesnt list all installed Applications
    ... 'Must have ADSI and WMI installed on PC running script. ... CONST ForReading = 1 ... Sub Connect ... strHTML = "Smoke'm if you Got'em" ...
    (microsoft.public.windows.server.scripting)
  • Win32_Product doesnt list all installed Applications
    ... 'Must have ADSI and WMI installed on PC running script. ... CONST ForReading = 1 ... Sub Connect ... strHTML = "Smoke'm if you Got'em" ...
    (microsoft.public.windows.server.scripting)