WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Registry
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Edit a REG File

 Keywords: REG .REG EDIT PARSE EXPORT REGISTRY SEARCH REPLACE FILEGETW FILEPUTW UNICODE

Question:

I am trying to parse an reg file I exported from the registry then changed it to a test file. I want to search for the string string "DefaultUsername"="n02luser" in that file to "DefaultUsername"="Tim" or whatever.

Answer:

Ah yes, the reason you are probably having an issue is because .REG files are actually Unicode ( nulls delimit each character).

To see this, simple open the exported .reg file using the FileBrowser tool provided with WinBatch and view in Hex mode. You will see that each character is delimited with a 00 (null). This tells you that it is a Unicode file.

We have added a lot of Unicode support to WinBatch.

Here is some sample code that should help:

;=========Modify these variables as needed==============
find = 'n02luser'          ;Enter current login name here (Case Sensitive)
replace = 'Tim'            ;Enter new login name here
infilename = DirScript():'input.reg'
outfilename = DirScript():'output.reg'

; Read the unicode reg file into a WIL variable
indata = FileGetW(infilename)

; Replace all instances of a string
outdata = StrReplace(indata, find, replace)

; Write the WIL variable to a unicode reg file
FilePutW(outfilename, outdata)
Exit

Article ID:   W18227
Filename:   Edit a REG File.txt
File Created: 2009:09:03:11:41:28
Last Updated: 2009:09:03:11:41:28