Jump to content

Replace text in a REG file.


Recommended Posts

I am quite familiar with this well-known replace text solution:

$szText = FileRead($szFile,FileGetSize($szFile))
$szText = StringReplace($szText, "replace me", "with me")
FileDelete($szFile)
FileWrite($szFile,$szText)

Problem is, when I apply it to a REG file, it does not reconstruct the file correctly. I'm gonna have to include a screenshot for this one:

Posted Image

To the left is original, to the right - reconstructed. How would I edit the file maintaining its format?

P.S. Pardon me for the big image, I am not yet sure what is the hide tag in the forum.

Link to comment
Share on other sites

Files with the .reg extension are just INI files, you could try it using the INI* functions instead of StringReplace. Just a thought.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Ok, I think I found a solution. _ReplaceStringInFile. Testing now. If I'll have any further questions, I'll post them.

Files with the .reg extension are just INI files, you could try it using the INI* functions instead of StringReplace. Just a thought.

Thanks! I didn't... realize that, lol. So stupid of me...

I need to edit this particular part though:

[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionMMDevicesAudioRender{199da893-117f-497d-aa29-03efab96c7bf}FxProperties]

It wouldn't be a typical value/data edit.

Yup, _ReplaceStringInFile did it, maintaining the original file structure. Great.

Edited by supraspecies
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...