[Solved]How to call WinApi function to change the owner of a registry key

Windows specific forum
Zero Ray
User
User
Posts: 12
Joined: Sat Jan 06, 2024 7:02 am

[Solved]How to call WinApi function to change the owner of a registry key

Post by Zero Ray »

How do I call the SetNamedSecurityInfo_ function to change the owner of a registry key to SYSTEM?

Solved

Example

Code: Select all

EnableExplicit

#SE_REGISTRY_KEY = $4
#OWNER_SECURITY_INFORMATION = $1

Define SECURITY_NT_AUTHORITY.SID_IDENTIFIER_AUTHORITY, *pSid, tmp.i

SECURITY_NT_AUTHORITY\Value[5] = 5

If AllocateAndInitializeSid_(@SECURITY_NT_AUTHORITY, 1, 18, 0, 0, 0, 0, 0, 0, 0, @*pSid)
  RtlAdjustPrivilege_(18, 1, 0, @tmp)
  Debug SetNamedSecurityInfo_("MACHINE\SOFTWARE\ExampleRegKey", #SE_REGISTRY_KEY, #OWNER_SECURITY_INFORMATION, *pSid, #Null, #Null, #Null)
  RtlAdjustPrivilege_(18, 0, 0, @tmp)
  FreeSid_(*pSid)
EndIf
Last edited by Zero Ray on Sat Aug 02, 2025 6:51 am, edited 2 times in total.
User avatar
jacdelad
Addict
Addict
Posts: 2000
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: How to call WinApi function to change the owner of a registry key

Post by jacdelad »

Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Zero Ray
User
User
Posts: 12
Joined: Sat Jan 06, 2024 7:02 am

Re: How to call WinApi function to change the owner of a registry key

Post by Zero Ray »

Can you give some examples?
Post Reply