Restore registry key with security settings

Reg format have two problems when you try to import file to registry:

  • doesnt contain security settings
  • it is using merge instead of replace

This can be sometimes really unwelcomed - for example you want to automatically recreate ODBC settings everytime user logs on. What do you do? You create odbc.reg and automatically import it every time... Wrong! The problem is that if users creates some additional odbc sources, they will stay. Ok, so how can you completely overwrite the key???

In fact it is quite simple - instead of using .reg, you should use hive keys (.hiv). You can do it from regedit or if you prefer console, use Reg.exe instead (with Save/Restore switches).

I used this few times and it is really useful! In hive file, there are also informations about security settings, so you can easily create them.

This is sometimes really useful - hope so that it could help someone fighting with registry ;)

Published Tue, Apr 18 2006 12:47 by martin

Comments

# re: Restore registry key with security settings

Using hives like this is not a good idea in my opinion. You may run into problem with SID's being different between machines and Domains. Sounds like a strange problem just waiting to happen.

Couldn't you just make a reg file that deletes the key first, then load it?

Windows Registry Editor Version 5.00

[-HKEY_CURRENT_USER\Software\ODBC]

[HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\dBASE Files]
"Driver"="C:\\WINDOWS\\system32\\odbcjt32.dll"
"DriverId"=dword:00000215
"SafeTransactions"=dword:00000000
"UID"=""

Thursday, April 20, 2006 5:02 PM by Noise

# re: Restore registry key with security settings

Hmmmm, why would you run into problems? There shouldnt be SID inside hive files - or am I wrong and there is (as always) something new I can learn? :)

Martin

Monday, April 24, 2006 9:19 AM by martin

# re: Restore registry key with security settings

Yes. Hive files contain the security settings for the registry keys inside it. Of course, they are stored as SIDS.

It is possible that reg.exe will strip the security information before importing the hive. I've never tested it.

Monday, April 24, 2006 5:36 PM by Noise