Sign in to follow this  
Followers 0
Tinywoods

To replace a phrase in a Reg file

5 posts in this topic

#1 ·  Posted (edited)

Hello :o

I made a script that export a part of registry and replace a phrase with another phrase. However, I really do NOT want to see any window during a script runs. I really want to do it in silent. The reg file is about 135KB. Is there any better way to do that? I don't use an English OS, so some of widows' name maybe wrong in the below my script. (I might mistake when I translate it to post the forum.) :">

#include <Process.au3>

; Export a part of Reg
$rc = _RunDos("REG EXPORT HKEY_CLASSES_ROOT\Installer\Products C:\WPI\NEROREG.reg")
$handle = "C:\WPI\NEROREG.reg"
$rename = "C:\WPI\NEROREG.txt"
$old = "Nero 7 Demo"
$new = "Nero 7.0.5.4 Premium Edition (demo)"


; Make a copied txt file of the reg file 
    If FileExists($handle) Then
    FileCopy($handle, $rename, 1)
    EndIf
Sleep(2000)


; Replace a phrase in the txt
If FileExists($rename) Then
    Run("notepad.exe C:\WPI\NEROREG.txt")
    WinWait("NEROREG.txt - Notepad")
    Sleep(5000)
    Send("!e")
    Sleep(2000)
    Send("{R}")
    Sleep(5000)
        ControlSend("Replace", "", "Edit1", $old)
        Sleep(2000)
        ControlSend("Replace", "", "Edit2", $new)
        Sleep(2000)
        ControlClick("Replace", "", "Button5")
        Sleep(2000)
        ControlClick("Replace", "", "Button6")
        Sleep(2000)
        Send("^s") 
EndIf
Sleep(2000)

WinClose("NEROREG.txt - Notepad")
Sleep(2000)

; Make a copied reg file of the txt file 
FileCopy($rename, $handle, 1)

Sleep(2000)
; Import the modified new Reg
_RunDos("Regedit /s C:\WPI\NEROREG.reg")
Edited by Tinywoods

Share this post


Link to post
Share on other sites



Why not just use RegRead to check what is in the key and RegWrite to change it if it is not what you want.



Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi BigDod,

Thank you for your response. Yes, I agree with you to use Regread.

I did not mention that the script will be used in WPI (Windows XP Post Install Wizard).

In registry, HKEY_CLASSES_ROOT\Installer\Products\XXXXXXXXX.

"\XXXXXXXXX" is not fixed data and it is always changing installation by installation.

Therefore, it was difficult for me to use Regread or RegEnumKey.

In this case, I want to change below part.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Installer\Products\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX]
"ProductName"="Nero 7 Demo"

I'd like to have the below Reg.

[HKEY_CLASSES_ROOT\Installer\Products\XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX]
"ProductName"=" Nero 7.0.5.4 Premium Edition (demo)"
Edited by Tinywoods

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hey Tinywoods,

This should do it for you

$key = 'HKCR\Installer\Products'
$valuename = 'ProductName'
For $i = 1 To 1000
    $subkey = RegEnumKey($key, $i)
    If @error Then ExitLoop
    $data = RegRead($key & '\' & $subkey, $valuename)
    If Not @error Then
        If $data = 'Nero 7 Demo' Then
            $data = 'Nero 7.0.5.4 Premium Edition (demo)'
            RegWrite($key & '\' & $subkey, 'Reg_sz', $data)
            ExitLoop
        EndIf
    EndIf
Next
Edited by MHz

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Hello MHz, ;)

Thank you agin and again.

Nice ! it works !!

I just needed to add $valuename in a line of RegWrite. Then, it became perfect.

Your WPI.au3 (To find out the correct WPI.hta from CD-Drives) that you provided me still works fine, too. :o

I'm NOT still good at "LOOP" commands, sorry. :geek:

Edited by Tinywoods

Share this post


Link to post
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
Sign in to follow this  
Followers 0