使用C ++获取本地管理员用户的名称 [英] Get local administrators users' names using C++
本文介绍了使用C ++获取本地管理员用户的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否可以让巫婆用户属于我的本地管理员组并列出他们.有什么办法可以使用C ++做到这一点?可能有任何WinAPI方式吗?
I'm wondering if I can get witch users belongs to my local administrator group and list them. Is there any way to do that using C++? Any WinAPI way, maybe?
非常感谢.
推荐答案
您可以使用 NetUserGetLocalGroups 和 NetUserGetInfo 检索您的信息并检查
You can use NetUserGetLocalGroups and NetUserGetInfo to retrive your information and check the value of usri1_priv
in the USER_INFO_1 structure.
我认为类似的东西应该可以帮助您入门(摘自MSDN):
I think something like this should get you started (taken from MSDN):
BOOL IsUserAdmin(VOID)
/*++
Routine Description: This routine returns TRUE if the caller's
process is a member of the Administrators local group. Caller is NOT
expected to be impersonating anyone and is expected to be able to
open its own process and process token.
Arguments: None.
Return Value:
TRUE - Caller has Administrators local group.
FALSE - Caller does not have Administrators local group. --
*/
{
BOOL b;
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
PSID AdministratorsGroup;
b = AllocateAndInitializeSid(
&NtAuthority,
2,
SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS,
0, 0, 0, 0, 0, 0,
&AdministratorsGroup);
if(b)
{
if (!CheckTokenMembership( NULL, AdministratorsGroup, &b))
{
b = FALSE;
}
FreeSid(AdministratorsGroup);
}
return(b);
}
您也可以查阅此页面(虽然年代久远,但应该可以使用)
You can also consult this page (it's old, but it should work)
这篇关于使用C ++获取本地管理员用户的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文