Alan Peck wrote:
> Excuss my question, still awaiting arrival of Roth's book on the Win32
> extentions, probably going to arrive late April! :(
>
> How does one obtain the account name from the SID using
> Win32::LookupAccountSID(SYSTEM,SID,ACCOUNT,DOMAIN,SIDTYPE). The is not much
> information about the parameters in the online documentation.
LookupAccountSID or LookupAccountName ?
> I assume all to be scalers where: SYSTEM is the hostname; SID is the value I
> retrieved from the Registry; ACCOUNT, DOMAIN, SIDTYPE are references to be
> filled.
>
> When I pass the hostname and SID, none of the other 3 parameters gets filled.
> The SID is in the long format of digits and hyphens. What could I be doing
> wrong?
use strict;
use warnings;
use Win32;
use Win32::API;
my $account = shift || 'Administrator';
my $server = shift || Win32::NodeName;
my ($domain, $binSID, $typeSID);
# need to get a binary SID so we can do your LookupAccountSID
Win32::LookupAccountName($server, $account, $domain, $binSID,
$typeSID) or die "Win32::LookupAccountName: $! ($^E)";
# convert the SID so we can print it later
my $ConvertSIDToStringSID = Win32::API->new('ADVAPI32.DLL',
'ConvertSidToStringSid', 'PP', 'N') or
die "Import ConvertSidToStringSid: $!";
my $StringSID = pack 'p', 0;
$ConvertSIDToStringSID->Call($binSID, $StringSID) or die
"ConvertSIDToStringSID->Call(): $!";
my $SID = unpack 'p', $StringSID;
# do your lookup now
Win32::LookupAccountSID($server, $binSID, $account, $domain, $typeSID)
or die "Win32::LookupAccountSID: $! ($^E)";
# print it all out except the binary SID
my %SIDtypes = (1 => 'User', 2 => 'Group', 3 => 'Domain', 4 => 'Alias',
5 => 'WellKnownGroup', 6 => 'DeletedAccount', 7 => 'Invalid', 8 => 'Unknown',
);
print "\n";
print "Account='$account', server='$server', domain='$domain'\n";
print "SIDtype = '$SIDtypes{$typeSID}, SID = '$SID'\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)
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs