Uff.. hoffen wir mal dass Coding Status: Still beginner nicht mehr ganz zutrifft

Ansonsten hast du dir da keine leichte API rausgepickt, aber ich habe dir mal einen Examplecode gebastelt und kommentiert:
Code: Alles auswählen
EnableExplicit
; Constants
#SDDL_REVISION_1 = 1
#DACL_SECURITY_INFORMATION = 4
; Defines
Define newKey.l, keyInfo.l, testString.s, libraryID.l
Define securityAttr.SECURITY_ATTRIBUTES, daclString.s
; Load some functions out of advapi32.dll
libraryID.l = OpenLibrary(#PB_Any, "advapi32.dll")
If IsLibrary(libraryID)
; Define a prototype
Prototype.l ptConvertStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor.s, StringSDRevision.l, SecurityDescriptor.l, SecurityDescriptorSize.l)
; Get the right function (ANSI or Unicode?)
Define ConvertStringSecurityDescriptorToSecurityDescriptor.ptConvertStringSecurityDescriptorToSecurityDescriptor
CompilerIf #PB_Compiler_Unicode = 0
ConvertStringSecurityDescriptorToSecurityDescriptor = GetFunction(libraryID, "ConvertStringSecurityDescriptorToSecurityDescriptorA")
CompilerElse
ConvertStringSecurityDescriptorToSecurityDescriptor = GetFunction(libraryID, "ConvertStringSecurityDescriptorToSecurityDescriptorW")
CompilerEndIf
Else
; [TODO] Add some error handler if library can't be loaded
End
EndIf
; Delete old keys with wrong rights
; [ATTENTION] Only works when you've got the necessary rights - See below!
If RegOpenKeyEx_(#HKEY_CURRENT_USER, "Test", 0, #KEY_READ | #KEY_WRITE, @newKey)
RegDeleteKey_(@newKey, "Test")
EndIf
; Create the registry key with the necessary rights
If RegCreateKeyEx_(#HKEY_CURRENT_USER, "Test", 0, 0, #REG_OPTION_NON_VOLATILE, #KEY_ALL_ACCESS , 0, @newKey, @keyInfo) = #ERROR_SUCCESS
; Fill security attributes structure with default values
With securityAttr
\bInheritHandle = #False
\nLength = SizeOf(SECURITY_ATTRIBUTES)
EndWith
; Create DACL string
daclString.s = "D:P" ; Discretionary ACL
; ---------------------------------------
; DIFFERENT EXAMPLES
;
; DON'T JUST COPY & PASTE - CHOOSE ONE EXAMPLE CAREFULLY AND COMMENT THE OTHER EXAMPLES OUT
; ---------------------------------------
; Example 1 - block all access, only administrators could access (no read & no write for everyone else)
daclString.s + "(D;OICI;GA;;;BG)" ; Deny all access to built-in guests
daclString.s + "(D;OICI;GA;;;AN)" ; Deny all access to anonymous logons
daclString.s + "(D;OICI;GA;;;AU)" ; Deny all access to authenticated users
daclString.s + "(A;OICI;GA;;;BA)" ; Allow all access for administrators
; Example 2 - block all write access, only administrators could write (no write but read for everyone else)
daclString.s + "(A;OICI;GR;;;BG)" ; Allow all read access to built-in guests
daclString.s + "(A;OICI;GR;;;AN)" ; Allow all read access to anonymous logons
daclString.s + "(A;OICI;GR;;;AU)" ; Allow all read access to authenticated users
daclString.s + "(A;OICI;GA;;;BA)" ; Allow all access for administrators
; Example 3 - block everything & everyone
daclString.s + "(D;OICI;GA;;;BG)" ; Deny all access to built-in guests
daclString.s + "(D;OICI;GA;;;AN)" ; Deny all access to anonymous logons
daclString.s + "(D;OICI;GA;;;AU)" ; Deny all access to authenticated users
daclString.s + "(D;OICI;GA;;;BA)" ; Deny all access for administrators
; ---------------------------------------
; END OF DIFFERENT EXAMPLES
; ---------------------------------------
; Convert DACL string to security descriptor
ConvertStringSecurityDescriptorToSecurityDescriptor(daclString, #SDDL_REVISION_1, @securityAttr\lpSecurityDescriptor, 0)
; Set security descriptor & close the registry key
RegSetKeySecurity_(newKey, #DACL_SECURITY_INFORMATION, securityAttr\lpSecurityDescriptor)
; [IMPORTANT] AFTER everything, create the desired keys
testString = "4 PureBoard" + Str(Random(9999))
RegSetValueEx_(newKey, "test", 0, #REG_SZ, @testString, Len(testString) + 1)
; Close the key
RegCloseKey_(newKey)
EndIf
Ich bitte dich allerdings, den Code zu studieren und nicht nur zu kopieren & einfügen. Du kannst damit ziemlich dumme Dinge anstellen und es ist alles ein wenig kompliziert. Wenn du Verständnisfragen hast, frag ruhig nach! Bedenke, dass alle APIs aktuell direkt aufgerufen werden - Ohne Errorhandler, den du noch jeweils einbauen solltest. (Also nur weitermachen, wenn die API erfolgreich war!) Ausserdem musst du im Rechtebereich dir ein Beispiel raussuchen, du kannst nicht alle 3 drin haben, ansonsten wird regedit meckern dass du komisch angeordnete Berechtigungen hast

Dann noch ein paar Doku-Links:
RegCreateKeyEx_ Funktion
RegSetKeySecurity Funktion
SECURITY_DESCRIPTOR Struktur
Guter MSDN Artikel zu DACL, ACE etc. (Das sind die Formate für Dateirechte)
Das wärs dann auch "schon" mit der Fachliteratur. Ich hoffe du kannst mit all dem was anfangen, ansonsten frag ruhig nach. Aber wie angemerkt, ist keine leichte Funktion, habe jetzt selber ein rechtes Weilchen lang recherchiert bis ich all das zusammenhatte
