X
xformer
Hello everybody
from time to time a badly written installation program messes up the
registry and creates entries that not even the admin can read.
So I wrote a little program with VB Express 2008 that finds these unreadable
registry keys, sets ownership to the built-in admin group and sets the access
rights to "full control" for the built-in admin group and "read" for the
built-in user group.
Well, almost. There is one thing that I can't get working: If I have found a
registry key that not even the admin can read I need to open that key only
with the right to take ownership of the key. I must not demand read
permission since the admin can't read that key. This is explained for the
native Win32 API in the following KB article:
http://support.microsoft.com/kb/111546/en-us.
I tried to put that in VB .NET code in the following way:
Private Sub takeOwnership(ByRef key As RegistryKey, ByRef subKeyname As
String)
Dim subkey As RegistryKey
Dim rs As RegistrySecurity
subkey = key.OpenSubKey(subKeyname,
RegistryKeyPermissionCheck.ReadSubTree, RegistryRights.TakeOwnership)
rs = subkey.GetAccessControl()
rs.SetOwner(m_sidAdminsGroup)
subkey.SetAccessControl(rs)
subkey.Close()
End Sub
Unfortunately this comes up with a SecurityException at key.OpenSubKey. It
seems as if OpenSubKey tries to open the key with read access despite the
fact that I only demanded RegistryRights.TakeOwnership.
MS documentation is woefully inadequate at this topic and I could not find
anything that would help me on the web.
Does anybody have an idea how to get this working in .NET? Any help would be
greatly appreciated.
Regards,
Frank
from time to time a badly written installation program messes up the
registry and creates entries that not even the admin can read.
So I wrote a little program with VB Express 2008 that finds these unreadable
registry keys, sets ownership to the built-in admin group and sets the access
rights to "full control" for the built-in admin group and "read" for the
built-in user group.
Well, almost. There is one thing that I can't get working: If I have found a
registry key that not even the admin can read I need to open that key only
with the right to take ownership of the key. I must not demand read
permission since the admin can't read that key. This is explained for the
native Win32 API in the following KB article:
http://support.microsoft.com/kb/111546/en-us.
I tried to put that in VB .NET code in the following way:
Private Sub takeOwnership(ByRef key As RegistryKey, ByRef subKeyname As
String)
Dim subkey As RegistryKey
Dim rs As RegistrySecurity
subkey = key.OpenSubKey(subKeyname,
RegistryKeyPermissionCheck.ReadSubTree, RegistryRights.TakeOwnership)
rs = subkey.GetAccessControl()
rs.SetOwner(m_sidAdminsGroup)
subkey.SetAccessControl(rs)
subkey.Close()
End Sub
Unfortunately this comes up with a SecurityException at key.OpenSubKey. It
seems as if OpenSubKey tries to open the key with read access despite the
fact that I only demanded RegistryRights.TakeOwnership.
MS documentation is woefully inadequate at this topic and I could not find
anything that would help me on the web.
Does anybody have an idea how to get this working in .NET? Any help would be
greatly appreciated.
Regards,
Frank