Brian Rankin wrote:
> Hello,
>
> I'm trying to get the permissions on a share using WMI. I've used WMI
> successfully for many tasks, but this one is a bit problematic.
>
> The issue is how to call GetSecurityDescriptor in ActivePerl. I found a
> posting
> (http://www.mail-archive.com/[email protected]/msg03336.html)
>
> which indicates this uses a call-by-reference interface, which requires
> different handling. However, this doesn't work for me, as no data is
> returned.
>
> Any suggestions appreciated. Following is my code.
>
> Regards, Brian
>
>
> $shareSecCol = $WMI->ExecQuery("Select * from
> Win32_LogicalShareSecuritySetting where Name = 'TestShare'");
>
> foreach my $shareSecSetting (in($shareSecCol))
> {
> print "Name: $shareSecSetting->{Name}\n"; ## prints successfully
>
> # Ask the security setting object for the security descriptor.
> # The call-by-reference interface forces us to use a "Variant"
> # object here.
> my $var = Win32::OLE::Variant->new (VT_DISPATCH|VT_BYREF);
> my $ret = $shareSecSetting->GetSecurityDescriptor ($var);
>
> # Get the Win32_SecurityDescriptor from the variant.
> my $sd = $var->Get();
> print "SD: $sd\n"; ## Nothing is printed; s/b an object
>
> # Get the ACL, which is just an array of Win32_ACE objects.
> my @dacl = @{$sd->{'DACL'}};
> foreach my $ace (@dacl) ## This loop isn't entered
> {
> my $trustee = $ace->{'Trustee'};
> $name = $trustee->{'Name'};
> print "Name: $name\n";
> }
> }
Another incomplete snippet. Please make sure your snippet compiles
before posting.
What does this one yield for you :
use strict;
use Win32::OLE qw(in);
use Win32::OLE::Variant;
my $WMI = Win32::OLE->GetObject('winmgmts:') or die "GetObject: $!";
# my $Objs = $WMI->ExecQuery('Select * from Win32_LogicalShareSecuritySetting '
.
# "where Name = 'TestShare'");
# test with all since no TestShare here:
my $Objs = $WMI->ExecQuery('Select * from Win32_LogicalShareSecuritySetting');
foreach my $obj (in $Objs) {
print "Sec Setting Name: $obj->{Name}\n";
# Ask the security setting object for the security descriptor.
# The call-by-reference interface forces us to use a "Variant"
# object here.
my $var = Win32::OLE::Variant->new (VT_DISPATCH|VT_BYREF);
my $ret = $obj->GetSecurityDescriptor($var);
# Get the Win32_SecurityDescriptor from the variant.
my $sd = $var->Get();
# Get the ACL, which is just an array of Win32_ACE objects.
my @dacl = $sd->{'DACL'};
foreach my $ace (in @dacl) {
my $trustee = $ace->{'Trustee'};
my $name = $trustee->{'Name'};
print "\tTrustee Name: $name\n";
}
print "\n";
}
__END__
--
,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED]
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs