Renaming a registry key

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • searcher123
    Forum Member
    • Jun 2007
    • 59

    Renaming a registry key

    Dear users,
    I need rename a registry key without losing its sub keys. Is anyway for doing this work by Setup Factory 7.0? For example, Can I rename [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Sa feBoot\Minimal] to [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Sa feBoot\-Minimal] without losing subkeys?

    Thanks
    Best Regard
  • pww
    Indigo Rose Customer
    • Jun 2005
    • 470

    #2
    what you can do is to export the key to a .reg file using
    regedit /e file.reg keyToExport
    open the reg file with SF, replace key name with the new one, save it, delete old key and then merge the .reg file
    regedit /s file.reg

    Comment

    • searcher123
      Forum Member
      • Jun 2007
      • 59

      #3
      Thanks for your answer,
      In theory you are right, but there is some problem in practice.
      The biggest problem is Export feature of Regedit. When you export a key by /e argument, Regedit.exe adds some invisible codes to the exported file. These codes are a FFFE in the beginning of exported file and a 00 code between each character. Forgoing codes are not visible by any text editor, but Setup Factory's TextFile.ReadToTable() function can read these codes and failed to read an exported REG file to a table. If you open a REG file with a plain text editor (e.g Notpad or EditPad Pro) and save it again in another file without any change, the file size will be half, because these codes are omitted by text editors and TextFile.ReadToTable() can read it without any problem.

      The second problem is replacing a word on table dimensions. Apparently, String.Replace() function work just with a single string, not a table, because I receive an error on following code:

      strRegFile = _TempFolder.."\\test.reg"
      old_contents = TextFile.ReadToTable(strRegFile);
      new_contents = String.Replace(old_contents, "Minimal", "-Minimal", true);

      I think the replacing should be done dimension by dimension and it is not a fast idea. Oh my GOD! What was happend if SF7 had a RegKey.Rename() or RegKey.CopyAs() for these cases!

      I will be thanks for any suggestion for above problems.

      Best Regards

      Comment

      • pww
        Indigo Rose Customer
        • Jun 2005
        • 470

        #4
        so regedit /e creates a unicode file, not sure how SF handles these
        Try with TextFile.ReadToString() , this will return the whole file content in a single string and you can replace everything at once, no need to use tables.
        Also ReadToString may not be confused by unicode strings and be able to search/replace in them - if not, after reading the file to string try replacing all null characters with nothing to have a plain ascii string, and then replace the key name.

        Comment

        • searcher123
          Forum Member
          • Jun 2007
          • 59

          #5
          TextFile.ReadToString() have the same behavior as TextFile.ReadToTable() with REG files (albeit just with REG files exported under WinXP & 2000. Win98 & WinME have not this problems).

          I found a simple solution for renaming reg keys now. Unfortunately, this way work just under WinXP. The code is as follow:

          oldRegKey = "HKLM\\MyPath\\OldKeyName"
          newRegKey = "HKLM\\MyPath\\NewKeyName"

          result = File.Run("Reg Copy "..oldRegKey.." "..newRegKey.." /s", "", "", SW_MINIMIZE, true);

          Registry.DeleteKey(HKEY_LOCAL_MACHINE, oldRegKey);

          I Hope I find an alternative way for Win2000 too.

          Best Regards

          Comment

          • pww
            Indigo Rose Customer
            • Jun 2005
            • 470

            #6
            forgot about reg.exe

            Although it's not a part of the OS installation for pre-XP OS's, I guess it will work on any Windows.
            So you can simply include reg.exe as a primer file in your project, it will be extracted to templaunchfolder. If there is no existing reg.exe on the system, you can send commands to the one that comes with your installer.

            Comment

            • searcher123
              Forum Member
              • Jun 2007
              • 59

              #7
              Thanks again for your mention. Reg.exe worked under Win2000, but this program is a NT program and not worked under WinME/98 correctly. Unfortunately, I should use "Regedit /e" technique under win98/ME.

              Comment

              Working...
              X