Hello,
I need to programmaticall y take ownership of a registry-key as
current user using VB2005. To test this , i created a key
HKEY_LOCAL_MACH INE\Software\Te stKey and removed all accessrights from this
key using RegEdt32.
Now i tried to set the accessrights by my programm. Since i do not have
rights to this key, i cannot open the key to get a handle for modifying the
rights.
http://groups.google.com/group/micro...7d20dc77f98e8f
I use the code below to take ownership, but it will not work.
Could anyone tell how to modify it? Thank you very much.
////////////////////////////////////////////////
Dim user As Security.Princi pal.NTAccount = New
Security.Princi pal.NTAccount(E nvironment.User DomainName & "\" &
Environment.Use rName)
Dim subKey As String = "test"
Dim rk As RegistryKey = Registry.LocalM achine.OpenSubK ey(subKey,
RegistryKeyPerm issionCheck.Rea dSubTree,
Security.Access Control.Registr yRights.TakeOwn ership)
Dim rs As Security.Access Control.Registr ySecurity =
rk.GetAccessCon trol()
rs.SetOwner(use r)
MessageBox.Show ("done")