Gathering information about a workstation 

Some times you need information about a workstation, for example if you want to know if a workstation is not running WindowsNT and you try some NT-specific job without any chance. I think this pseudo-routine can be helpful. 

#include 

/*Usually:

#include 

#include 

#include 

#include */

// Network API job - obtain network info about selected machine.

BOOL

_GetWkstaInformation100()

{

LPBYTE lpBuf;

LPCSTR lpcstrWkstaName = (LPCSTR)m_strWkstaName;

int iwLength = 2 * (MAX_COMPUTERNAME_LENGTH + 1);

WCHAR lpwWkstaName[2 * (MAX_COMPUTERNAME_LENGTH + 1)];

lpwWkstaName[0] = '\0';

MultiByteToWideChar(CP_ACP, 0, lpcstrWkstaName, -1, lpwWkstaName, iwLength);

typedef NET_API_STATUS (NET_API_FUNCTION *NETWKPROC)(LPWSTR, DWORD, LPBYTE *);

NETWKPROC _procNetWkstaGetInfo = (NETWKPROC)

(GetProcAddress(theApp.m_hNetDLL, _T("NetWkstaGetInfo")));

if(_procNetWkstaGetInfo)

{

NET_API_STATUS nasRetVal = (*_procNetWkstaGetInfo)(lpwWkstaName, 100, (LPBYTE*)&lpBuf);

if(nasRetVal == NERR_Success)

{

WKSTA_INFO_100 *pWkstaInfo = (WKSTA_INFO_100 *)lpBuf;

DWORD dwPlatformId = pWkstaInfo->wki100_platform_id;

if(dwPlatformId != PLATFORM_ID_NT)

{

//[ERROR]Not a Windows NT Workstation - if useful.

return FALSE;

}

else

  return TRUE;

}

else

{

//[ERROR] System error. Call GetLastError, FormatMessage, etc.

return FALSE;

}

}

else

{

//[ERROR]Unable to find procedure NetWkstaGetInfo in netapi32.dll.

return FALSE;

}

}

History

Date Posted: June 8, 1999 

Last Updated: June 8, 1999