Help! VBScript text file read/write adding garbage on Japanese windows...

I have a very basic VBScript that's launched from our WISE Installer that does a search and replace on a text file on the user's system. The script works fine on US Windows, but for some reason on Japanese Windows, it inserts hex "81 00 45 00 BF 00" before the 3rd byte at the beginning of the first line in the file. I've searched the net and seen issues regarding reading and writing binary, but nothing about text...

The main code is thus:
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
LocaleLCID = WshShell.RegRead("HKEY_CURRENT_USER\Control Panel\International\Locale")

function UpdateVersionNumbers(sFileName, SearchText, ReplaceText)

Const ForReading = 1
Const ForWriting = 2

Set objFile = FileSystemObject.OpenTextFile(sFileName, ForReading)

strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, SearchText, ReplaceText)

Set objFile = FileSystemObject.OpenTextFile(sFileName, ForWriting)
objFile.WriteLine strNewText
objFile.Close

end function

Q/A found this at the last minute so I'm under the gun to fix it ASAP - any help folks could give would be most appreciated!


[3463 byte] By [StickyC] at [2007-12-24]
# 1

Hi StickyC,

Try replacing your...

objFile.WriteLine strNewText

with...

objFile.WriteLine(1, strNewText)

I hope this solves your problem.

Thank you,

James

ReaSoftwareEngineering at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2
Actually, it turns out the solution was to set the unicode format bit in the OpenTextFile call. The new code looks like:

function UpdateVersionNumbers(sFileName, SearchText, ReplaceText)

Const ForReading = 1
Const ForWriting = 2
Const Unicode = -1

Set objFile = FileSystemObject.OpenTextFile(sFileName, ForReading, Unicode)

strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, SearchText, ReplaceText)

Set objFile = FileSystemObject.OpenTextFile(sFileName, ForWriting, Unicode)
objFile.WriteLine strNewText
objFile.Close

end function

StickyC at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3

in future, any vbscripting questions should be posted here:

http://www.microsoft.com/technet/community/newsgroups/topics/scripting.mspx

ahmedilyas at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...