Sign in to follow this  
Followers 0
FredAI

Convert function SetNamedSecurityInfo doesn't work

3 posts in this topic

Hi all.

I'm trying to convert this function to AutoIt. I don't see any error, but it always return 87 (Invalid parameter in winerror.h) when I test.

Any ideas?

Thanks.

Fred

Global Const $DACL_SECURITY_INFORMATION = 4
Global Const $OWNER_SECURITY_INFORMATION  = 1
Global Const $GROUP_SECURITY_INFORMATION  = 2
Global Const $SACL_SECURITY_INFORMATION  = 8
Global Const $SE_SACL_PROTECTED = 8192
Global Const $SE_DACL_PROTECTED = 4096

Local $File = @ScriptDir&'\ND.txt'
Local $R = _WINAPI_SetNamedSecurityInfo($File,-1,$SE_DACL_PROTECTED)

 If IsArray($R) Then
    For $i = 0 To 7
        MsgBox(0,'',$R[$i])
    Next
EndIf

Func _WINAPI_SetNamedSecurityInfo(      $pObjectName, _
                                        $SE_OBJECT_TYPE, _
                                        $SECURITY_INFORMATION, _
                                        $psidOwner = '', _
                                        $psidGroup = '', _
                                        $pDacl = '', _
                                        $pSacl = '' _
)

    If $SE_OBJECT_TYPE = -1 Then $SE_OBJECT_TYPE = 'SE_FILE_OBJECT'
    
    Return DllCall('advapi32.dll',      'DWORD','SetNamedSecurityInfoW', _
                                        'str',$pObjectName, _
                                        'str',$SE_OBJECT_TYPE, _
                                        'int',$SECURITY_INFORMATION, _
                                        'ptr',$psidOwner, _
                                        'ptr',$psidGroup, _
                                        'ptr',$pDacl, _
                                        'ptr',$pSacl _
    )
EndFunc

Share this post


Link to post
Share on other sites



You are using 'str' as the type string but calling the unicode version of the function. Try:

Return DllCall('advapi32.dll',      'DWORD','SetNamedSecurityInfoW', _
                                        'wstr',$pObjectName, _
                                        'wstr',$SE_OBJECT_TYPE, _
                                        'int',$SECURITY_INFORMATION, _
                                        'ptr',$psidOwner, _
                                        'ptr',$psidGroup, _
                                        'ptr',$pDacl, _
                                        'ptr',$pSacl _
    )

You are also passing those pointers as strings by default, that shouldn't stop it working but standard practice is using zero instead.

Share this post


Link to post
Share on other sites

Thanks, Mat.

It still doesn't work. I guess I'll have to create the structures ant use a valid pointer.

Right now I'm too busy to continue with this project. As you may have guessed, I want to create an Autoit code replacement for setacl.exe.

I'll post back when I come back to this project.

Thanks again.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0