NetWkstaGetInfo() Program Example
The NetWkstaGetInfo() function returns information about the configuration of a workstation. The following code sample demonstrates how to retrieve information about the configuration elements for a workstation using a call to the NetWkstaGetInfo() function. The sample calls NetWkstaGetInfo(), specifying information level 102 (WKSTA_INFO_102). If the call succeeds, the sample prints information about the workstation. Finally, the code sample frees the memory allocated for the information buffer.
Create a new empty Win32 console application project. Give the project name and change the project location is needed.

Then, add the source file and give it a suitable name.

Then, add the following source code.
#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;
wprintf(LUsage: %s [\\\\ServerName]\n, argv[0]);
wprintf(LIf the server name not supplied, default to local computer\n\n);
// Check command line arguments.
if (argc > 2)
{
fwprintf_s(stderr, LUsage: %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)
{
wprintf(LNetWkstaGetInfo() is OK!\n);
wprintf(L\n\tPlatform: %d\n, pBuf->wki102_platform_id);
wprintf(L\tName: %s\n, pBuf->wki102_computername);
wprintf(L\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
{
wprintf(LNetWkstaGetInfo() failed!\n);
fwprintf_s(stderr, LA system error has occurred: %d\n, nStatus);
}
// Free the allocated memory.
if (pBuf != NULL)
NetApiBufferFree(pBuf);
return 0;
}
Build and run the project. The following screenshot is a sample output.
