From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.



怎样写程序来查询正在使用Windows的使用者有没有系统管理员权限



硬件: PXI/CompactPCI>>Controllers

问题: 在很多程序中, 我们会需要知道使用者是否有系统管理员权限. 怎样写一个程序来做到?

解答: 请使用以下的程序. 此程序会回传"True"如果使用者有系统管理员权限.

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);
}

附件中有此程式的DLL与一个使用此DLL的VI. 附件的运行系统有Windows XP, Windows 2000 Professional, 和 Windows Server 2000, 2003.


相关链接:

附件:


Check Admin.rar - Check Admin.rar


报告日期: 06/01/2004
最近更新: 01/21/2009
文档编号: 3A019LFE