The call that's failing is RegSetKeySecurity(). It takes in a handle of an already open registry key, a dword stating what your going to Set, and then the Security Descriptor to apply to that key. After I create the Security Descriptor, I test if it is ok with IsValidSecurityDescriptor, and it passes that check, so I know it should be ok. I copied my registry opening call above it (RegOpenKeyEx()) to another file, read other keys, counted subkeys, closed the key, etc... And the middle parameter, for all my searching, is just 4. But, even with all this checking and knowing things should be right, it still errors out with the invalid parameter.
I'm still stumped. I'm going to post here the code that's erroring out specifically, and attach the entire script too. I hope someone else can figure this out, I'm just stumped.
Local $handle = DllStructCreate ("ptr") $err = DllCall("Advapi32.dll", "long", "RegOpenKeyEx", _ "ptr", 0x80000002, _ "str", $npath, _ ; string containing path to Registry Key to be opened "dword", 0, _ "long", $WRITE_DAC, _ "ptr", DllStructGetPtr ($handle)) If $err[0] <> 0 Then ConsoleWrite('RegOpenKeyEx Failed with error ' & $err[0] & @CRLF) MsgBox(0,'Error','RegOpenKeyEx Failed with error ' & $err[0]) Exit EndIf $err = DllCall("Advapi32.dll","long","RegSetKeySecurity", _ "ptr", DllStructGetData($handle,1), _ "dword", $WRITE_DAC, _ "ptr", DllStructGetPtr($sdout)) If $err[0] <> 0 Then ConsoleWrite('RegSetKeySecurity Failed with error ' & $err[0] & @CRLF) DllCall('AdvAPI32.dll','Long','RegCloseKey','ptr',DllStructGetData($handle,1)) MsgBox(0,'Error','RegSetKeySecurity Failed with error ' & $err[0]) Exit EndIf DllCall('AdvAPI32.dll','Long','RegCloseKey','ptr',DllStructGetData($handle,1))
Thank anyone for any and all help they can give me. Like I said, this is just for my learning, and I do know of other solutions (mscacls.exe, the COM object that ptrex has shown), but none of those solutions can be easily installed/used, plus they use these same methods to do what they do, so I might as well cut out the middle man. Not to mention I don't want to have to install any more files, I like one file that can do everything I need it too, and I'm so close to that.
Attached Files
Edited by SkinnyWhiteGuy, 07 December 2007 - 01:01 PM.






