NetWkstaGetInfo获取系统版本信息
2024-02-18
13
0
NetWkstaGetInfo可用获取操作系统的基本信息:
#pragma comment(lib, "netapi32.lib")
#include <lm.h>
void OSInfo()
{
DWORD dwLevel = 102;
LPWKSTA_INFO_102 pBuf = NULL;
NET_API_STATUS nStatus;
LPWSTR pszServerName = NULL;
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);
}
Windows10输出结果:
Platform: 500
Name: DESKTOP-Q25N19N
Version: 10.0
Domain: WORKGROUP
Lan Root:
# Logged On Users: 2