A company I work for sometimes uses super mandatory profiles for their users. Unfortunately this can cause lots of issues with user settings not being saved at log off and so on. To work around this a .reg file is run at startup. For some of these settings regmon was used to record making the settings change and a reg file created from this. The trouble with this is their are lots of duplicate entries making it larger and larger each time this has been done. By the way I didn’t implement this procedure I just have to live with it.
I am going to attempt to clean this down to it’s minimum but am wondering if anyone has done this before. What I am thinking is, I read the lines into an 2d array so:
[HKEY_CURRENT_USER\Software\CELCAT\CT\SAT\Settings]
“OpenTTVS”=”0”
“OTTFrmW”=”420”
“OTTFrmH”=”321”
becomes:
[HKEY_CURRENT_USER\Software\CELCAT\CT\SAT\Settings], “OpenTTVS”=”0”
[HKEY_CURRENT_USER\Software\CELCAT\CT\SAT\Settings], “OTTFrmW”=”420”
[HKEY_CURRENT_USER\Software\CELCAT\CT\SAT\Settings], “OTTFrmH”=”321”
Then remove duplicates in reverse order so if a setting is changed twice it removes the entries first in the file.
Then sort the array by the hive and output the key every time and the hive when it changes. Sorry if the terminology is wrong.
Will this work? Probably better using a collection rather than an array but you get the idea.
For a first try i would read this .reg file into a tree, just the way regedit looks like. By building up the tree you just check if a node exists. If not, created it else overwrite the existing value.
So you’ll get just the last entry which take into effect. After creating this tree, you’ll have to read back the current tree and you’re ready.
While writing this, i’ll got another idea:
Open the .reg file in a texteditor. Replace “[HKEY_CURRENT_USER\” against “[HKEY_CURRENT_USER\JustSomeKeyThatDoesNotExists” and import this file into the registry. Now open the registry and export the whole “[HKEY_CURRENT_USER\JustSomeKeyThatDoesNotExists” back into a file. Open the file and make the first replacement backwards.
Now you’ll have a file with unique value in a sorted order. ;-))