从本地管理员组中获取用户 [英] Fetch users from local administrator group

查看:183
本文介绍了从本地管理员组中获取用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Guys,



我正在尝试用C ++编写代码来从本地管理员组中获取用户。在编译时我收到链接器错误说

Hello Guys,

I'm trying to write a code in C++ to fetch users from local administrators group. While compiling I get a linker error saying

D:\Reference\CCPP\Get Local Admin Users\main.o	main.c:(.text+0x68): undefined reference to `NetLocalGroupGetMembers'





lmaccess.h文件确实有这个函数的声明。没有出错的地方。





lmaccess.h file do have a declaration for this function. Not getting where it is going wrong.

#include <stdio.h>
#include <windows.h>
#include <lmaccess.h>

int main(int argc, char **argv)
{
	LPCWSTR servername = NULL;
	LPCWSTR *localgroupname = (LPCWSTR *)"Administrators";
	DWORD LEVEL = 0;
	LPBYTE *bufptr;
	LPDWORD entriesread;
	LPDWORD totalentries;
	NET_API_STATUS RET;
	
	RET = NetLocalGroupGetMembers(servername, *localgroupname, LEVEL, bufptr, MAX_PREFERRED_LENGTH, entriesread, totalentries, 0);
	
	return 0;
}





我的尝试:



已验证lmaccess.h具有函数NetLocalGroupGetMembers的声明。



What I have tried:

Verified that lmaccess.h has the declaration for the function "NetLocalGroupGetMembers".

推荐答案

请参阅MSDN,了解 ^ ]。它声明该函数位于 Netapi32.dll 中。因此,您必须将您的应用程序与该DLL链接。最简单的解决方案是在您的一个源文件中使用pragma语句(另请参阅 comment(C / C ++) [ ^ ]):

See the MSDN for the used function at NetLocalGroupGetMembers function (Windows)[^]. It states that the function is located in the Netapi32.dll. So you have to link your application against that DLL. The simplest solution is using a pragma statement in one of your source files (see also comment (C/C++)[^]):
#pragma comment(lib, "Netapi32")



或者使用项目设置将其添加到项目中。


Alternatively add it to your project using the project settings.


这篇关于从本地管理员组中获取用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆