NetQueryDisplayInformation用法

以下代码示例演示如何使用对NetQueryDisplayInformation函数的调用返回组帐户信息 。如果用户指定了服务器名称,则示例首先调用 MultiByteToWideChar函数将名称转换为 Unicode。该示例调用 NetQueryDisplayInformation,指定信息级别 3 ( NET_DISPLAY_GROUP ) 以检索组帐户信息。如果有条目要返回,则示例返回数据并打印组信息。最后,代码示例释放为信息缓冲区分配的内存。

#ifndef UNICODE
#define UNICODE
#endif

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

#pragma comment(lib, “netapi32.lib”)

void main( int argc, char *argv[ ] )
{
PNET_DISPLAY_GROUP pBuff, p;
DWORD res, dwRec, i = 0;
//
// You can pass a NULL or empty string
// to retrieve the local information.
//
TCHAR szServer[255]=TEXT("");

if(argc > 1)
//
// Check to see if a server name was passed;
// if so, convert it to Unicode.
//
MultiByteToWideChar(CP_ACP, 0, argv[1], -1, szServer, 255);

do // begin do
{
//
// Call the NetQueryDisplayInformation function;
// specify information level 3 (group account information).
//
res = NetQueryDisplayInformation(szServer, 3, i, 1000, MAX_PREFERRED_LENGTH, &dwRec, (PVOID*) &pBuff);
//
// If the call succeeds,
//
if((resERROR_SUCCESS) || (resERROR_MORE_DATA))
{
p = pBuff;
for(;dwRec>0;dwRec–)
{
//
// Print the retrieved group information.
//
printf(“Name: %S\n”
“Comment: %S\n”
“Group ID: %u\n”
“Attributes: %u\n”
“--------------------------------\n”,
p->grpi3_name,
p->grpi3_comment,
p->grpi3_group_id,
p->grpi3_attributes);
//
// If there is more data, set the index.
//
i = p->grpi3_next_index;
p++;
}
//
// Free the allocated memory.
//
NetApiBufferFree(pBuff);
}
else
printf(“Error: %u\n”, res);
//
// Continue while there is more data.
//
} while (res==ERROR_MORE_DATA); // end do
return;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值