随笔 - 547  文章 - 213 评论 - 417 阅读 - 107万

MFC获得当前用户等信息

#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;

}

 

来自: https://msdn.microsoft.com/en-us/library/windows/desktop/aa370663(v=vs.85).aspx

posted on   今夜太冷  阅读(268)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示