Windows 使用Perl从SID获取帐户名
在我的Windows 10计算机上,我使用Win32::LookupAccountSID()按帐户获取SID。在cmd.exe中,我运行:Windows 使用Perl从SID获取帐户名,windows,perl,Windows,Perl,在我的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-
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转换为二进制格式。以下是使用模块转换为二进制格式的示例:
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'
};
我认为您输入到函数的SID应该不同。如果我使用Win32::LookupAccountName()获取SID,它看起来就完全不同了。在我的机器上,我得到了SID=`iji'.-╧≥Hπ┐ΘΦo-√╪奥切赫≈% ΦÖΦo x7σ╗╒奥普≈! ΦÖΦÖΦo╪>! └9# Φ=" °% ╪>! τz┘o└9#Φoαÿ╖≡o√a B■╠哦╛Y└uΦ=”└9# 9 \\╫≥o Xd4áÜ4Φo r═oΦo@n╕²aαa`如果我使用上述SID(而不是从
whoami
返回的SID)作为LookupAccountSID()
的输入,它工作得很好。您知道是否可以转换S-1-15-21格式(whoami格式)你提到的格式?你没有,是吗?我看,但如果它是用Win32单独完成的,它将是伟大的,因为它是核心的一部分。