在Windows 10计算机上,我使用Win32::LookupAccountSID()
通过帐户获取SID。在cmd.exe中,我运行:
whoami /user
我从输出中获取SID,并在下面的$sid
变量中使用它,但是打印的帐户为空,知道脚本有什么问题吗?use strict;
use warnings;
use Win32;
my $account;
my $domain;
my $sidtype;
my $sid = 'S-1-5-21-1994326832-1066739575-5522801-113721';
Win32::LookupAccountSID(undef,$sid,$account,$domain,$sidtype);
print $account;
最佳答案
您需要在调用Win32::LookupAccountSID()
之前将SID转换为二进制格式。这是一个使用 Win32::Security::SID
模块转换为二进制格式的示例:
use strict;
use warnings;
use Win32;
use Win32::Security::SID;
use Data::Dumper qw(Dumper);
{
my $system = undef;
my $account;
my $domain;
my $sidtype;
my $stringsid = 'S-1-5-21-1768581528-3487803020-3219343602-1001';
my $sid = Win32::Security::SID::ConvertStringSidToSid($stringsid);
Win32::LookupAccountSID($system, $sid, $account, $domain, $sidtype);
print Dumper({account => $account, domain => $domain, sidtype => $sidtype});
}
输出:$VAR1 = {
'domain' => 'DESKTOP-43CR0B8',
'sidtype' => 1,
'account' => 'hakon'
};
关于windows - 使用Perl从SID获取帐户名,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/63040930/