从Windows API获取计算机的域名 [英] Get the domain name of a computer from Windows API

查看:51
本文介绍了从Windows API获取计算机的域名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我需要知道计算机是否是某个域的主域控制器,所以我需要知道计算机的域才能调用NetGetDCName函数.

In my application I need to know if the computer is the primary domain controller of a domain, so I need to know the domain of the computer to call NetGetDCName function.

谢谢.

问题与DCOM身份验证有关,因此,如果我需要使用计算机的本地身份验证数据库,则在PDC情况下我需要知道要使用DOMAIN \ USERNAME的域,而在计算机\ USERNAME中,我需要知道该域.

The problem is related with the DCOM authentication so I need to know the domain to use the DOMAIN\USERNAME in case of a PDC or COMPUTER\USERNAME if I need to use the local authentication database of the computer.

推荐答案

我会考虑使用

I would consider using NetWkstaGetInfo() and pass the local computer name is that first parameter.

#include <Lmwksta.h>
#include <StrSafe.h>

WCHAR domain_name[256];
WKSTA_INFO_100 info = {0};
if (NERR_Success == NetWkstaGetInfo(L"THIS-COMPUTER", 100, &info) && 
    SUCCEEDED(StringCchCopy(domain_name, ARRAYSIZE(domain_name), info.wki100_langroup))) {
    // use domain_name here...
}

这篇关于从Windows API获取计算机的域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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