Because you are not using strict or warnings, you cannot see that DACL_SECURITY_INFORMATION is not defined. This results in $pSecDesc containing the wrong data, which cannot be decoded.
Adding this line populates $pSecDesc correctly:

use Win32 qw( DACL_SECURITY_INFORMATION );

You still need to decode the Security Descriptor; this (thrown together, barely tested) program may help:

use strict; use warnings; use Data::Dumper; $Data::Dumper::Useqq = 1; $| = 1; my $host = '127.0.0.1'; my $reg_key = 'SOFTWARE\\7-zip'; use Win32 qw( DACL_SECURITY_INFORMATION ); use Win32API::Registry 0.21 qw( :ALL ); # Get the Security Descriptor my $reg_api; RegConnectRegistry( $host, HKEY_LOCAL_MACHINE, $reg_api ) or die $^E; my $key; RegOpenKeyEx( $reg_api, $reg_key, 0, KEY_READ, $key ) or die $^E; my $pSecDesc; RegGetKeySecurity( $key, DACL_SECURITY_INFORMATION, $pSecDesc ) or die + $^E; # Print the raw DACL. print "\n", Dumper $pSecDesc; # Decode the Security Descriptor use Win32::API; use constant SDDL_REVISION_1 => 0x1; my $ConvertSDToString = Win32::API->new( 'ADVAPI32', 'ConvertSecurityDescriptorToStringSecurityDescriptor', ['P', 'N', 'N', 'P', 'N'], 'N', ); my $ptr_strSDDL = pack 'L', 0; # DWORD; my $ObjSD = $ConvertSDToString->Call( $pSecDesc, SDDL_REVISION_1, 0xF, $ptr_strSDDL, 0, ) or die $^E; my $strSDDL = unpack 'p', $ptr_strSDDL; # Print the decoded DACL. print "\n", Dumper $strSDDL;


In reply to Re: Win32API::Registry::RegGetKeySecurity how to unpack the structure of $pSecDesc? by Util
in thread Win32API::Registry::RegGetKeySecurity how to unpack the structure of $pSecDesc? by Sioln

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.