获取计算机域sid [英] get computer domain sid

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

问题描述

我想获得一个计算机域sid,而不使用lookupaccountname

问题是,如果在关闭域控制器的情况下启动计算机,则失败.

即使计算机断开连接或域控制器关闭,我也想获取域sid.

它是存储还是缓存在注册表中的任何位置,因为即使由于用户缓存而关闭计算机,我也能够在域中登录...所以我认为计算机的域sid也缓存在某个地方.

有没有可以给我域sid的API.

我希望它可以在winxp和win7及更高版本上工作.

hi i want to get a computer domain sid without using lookupaccountname

problem is it fails if the computer boots up when the domain controller is off.

i want to get the domain sid even when machine disconnected or domain controller is off.

is it stored or cached any where in registry because i am able to login in domain even when computer is off because the user is cached ...so i think domain sid of machine is also cached somewhere.

is there any api which can give me domain sid.

i want it to work on winxp and win7 and above.

推荐答案

ifndef UNICODE
#define UNICODE
#endif
#pragma comment(lib,"netapi32.lib")
#include< stdio.h>
#include< windows.h>
#include< lm.h>
int wmain(int argc,wchar_t * argv [])
{
DWORD dwLevel = 102;
LPWKSTA_INFO_102 pBuf = NULL;
NET_API_STATUS nStatus;
LPWSTR pszServerName = NULL;
//
//检查命令行参数.
//
如果(argc> 2)
{
fwprintf(stderr,L用法:%s [\\\\ ServerName] \ n",argv [0]);
exit(1);
}
//服务器不是默认的本地计算机.
//
如果(argc == 2)
pszServerName = argv [1];
//
//调用NetWkstaGetInfo函数,指定级别102.
//
nStatus = NetWkstaGetInfo(pszServerName,
dwLevel,
(LPBYTE *)& pBuf);
//
//如果通话成功,
//打印工作站数据.
//
如果(nStatus == NERR_Success)
{
printf("\ n \ tPlatform:%d \ n",pBuf-> wki102_platform_id);
wprintf(L"\ tName:%s \ n",pBuf-> wki102_computername);
printf("\ tVersion:%d.%d \ n",pBuf-> wki102_ver_major,
pBuf-> wki102_ver_minor);
wprintf(L"\ tDomain:%s \ n",pBuf-> wki102_langroup);
wprintf(L"\ tLan Root:%s \ n",pBuf-> wki102_lanroot);
wprintf(L"\ t#已登录用户:%d \ n",pBuf-> wki102_logged_on_users);
}
//
//否则,指示系统错误.
//
其他
fprintf(stderr,发生系统错误:%d \ n",nStatus);
//
//释放分配的内存.
//
如果(pBuf!= NULL)
NetApiBufferFree(pBuf);
返回0;
}
ifndef UNICODE
#define UNICODE
#endif
#pragma comment(lib, "netapi32.lib")
#include <stdio.h>
#include <windows.h>
#include <lm.h>
int wmain(int argc, wchar_t *argv[])
{
DWORD dwLevel = 102;
LPWKSTA_INFO_102 pBuf = NULL;
NET_API_STATUS nStatus;
LPWSTR pszServerName = NULL;
//
// Check command line arguments.
//
if (argc > 2)
{
fwprintf(stderr, L"Usage: %s [\\\\ServerName]\n", argv[0]);
exit(1);
}
// The server is not the default local computer.
//
if (argc == 2)
pszServerName = argv[1];
//
// Call the NetWkstaGetInfo function, specifying level 102.
//
nStatus = NetWkstaGetInfo(pszServerName,
dwLevel,
(LPBYTE *)&pBuf);
//
// If the call is successful,
// print the workstation data.
//
if (nStatus == NERR_Success)
{
printf("\n\tPlatform: %d\n", pBuf->wki102_platform_id);
wprintf(L"\tName: %s\n", pBuf->wki102_computername);
printf("\tVersion: %d.%d\n", pBuf->wki102_ver_major,
pBuf->wki102_ver_minor);
wprintf(L"\tDomain: %s\n", pBuf->wki102_langroup);
wprintf(L"\tLan Root: %s\n", pBuf->wki102_lanroot);
wprintf(L"\t# Logged On Users: %d\n", pBuf->wki102_logged_on_users);
}
//
// Otherwise, indicate the system error.
//
else
fprintf(stderr, "A system error has occurred: %d\n", nStatus);
//
// Free the allocated memory.
//
if (pBuf != NULL)
NetApiBufferFree(pBuf);
return 0;
}


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

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