Querying NT

Querying NT

Is there a way to query NT 4.0 (programmatically or manually) to have it tell me whether it is NT workstation or NT server? Is the answer in the system registry or in the OS itself?

Yes, the following code should work for you. Note that this assumes that anything that isn’t a NT server is a NT workstation, so if that’s not true, you might want some further checks and a return of other than a boolean value.


Option Explicit' Constants for type of computerPrivate Enum enumServerType   SV_TYPE_WORKSTATION = &H1&   SV_TYPE_SERVER = &H2&   SV_TYPE_SQLSERVER = &H4&   SV_TYPE_DOMAIN_CTRL = &H8&   SV_TYPE_DOMAIN_BAKCTRL = &H10&   SV_TYPE_NOVELL = &H80&   SV_TYPE_NT = &H1000&   SV_TYPE_WFW = &H2000&   SV_TYPE_SERVER_NT = &H8000&   SV_TYPE_WINDOWS = &H400000   SV_TYPE_ALL = &HFFFFEnd Enum' Type used by NetServerGetInfo and NetServerSetInfoPrivate Type SERVER_INFO_101    sv101_platform_id As Long    sv101_name As Long    sv101_ver_major As Long    sv101_ver_minor As Long    sv101_type As Long    sv101_comment As LongEnd Type      ' API declarationsPrivate Declare Function NetServerGetInfo _   Lib "Netapi32" _      (sServerName As Byte, _       ByVal lLevel As Long, _       vBuffer As Long) As LongPrivate Declare Function NetApiBufferFree _   Lib "netapi32.dll" _   (ByVal lngPtrBuffer As Long) As LongPrivate Declare Function lstrlenW _   Lib "kernel32" _   (ByVal lpString As Long) As LongPublic Declare Sub CopyMem _   Lib "kernel32" Alias "RtlMoveMemory" _   (dest As Any, vSrc As Any, ByVal lSize As Long)Public Sub Main()   Debug.Print IsServer("")   Debug.Print IsServer("PDCNew")End SubPublic Function IsServer(Optional ByVal xi_strServerName As String = "") As Boolean   Dim p_bytServerName()         As Byte   Dim p_lngRtn                  As Long   Dim p_lngSrvInfoRtn           As Long   Dim p_typServerInfo101        As SERVER_INFO_101   Dim p_lngServEnumLevel        As Long      ' Initialize the variables   If Trim$(xi_strServerName) = vbNullString Then      p_bytServerName = vbNullChar   Else      p_bytServerName = Trim$(xi_strServerName) & vbNullChar   End If   p_lngServEnumLevel = 101     ' Call NetServerEnum to get a list of Servers   If Trim$(xi_strServerName) = vbNullString Then      p_lngRtn = NetServerGetInfo(sServerName:=ByVal p_bytServerName(0), _                                  lLevel:=p_lngServEnumLevel, _                                  vBuffer:=p_lngSrvInfoRtn)   Else      p_lngRtn = NetServerGetInfo(sServerName:=p_bytServerName(0), _                                  lLevel:=p_lngServEnumLevel, _                                  vBuffer:=p_lngSrvInfoRtn)   End If      If p_lngRtn = 0 Then      ' xxx      CopyMem p_typServerInfo101, _              ByVal p_lngSrvInfoRtn, _              Len(p_typServerInfo101)      If p_typServerInfo101.sv101_type And enumServerType.SV_TYPE_SERVER_NT Then         IsServer = True      ElseIf p_typServerInfo101.sv101_type And enumServerType.SV_TYPE_DOMAIN_BAKCTRL Then         IsServer = True      ElseIf p_typServerInfo101.sv101_type And enumServerType.SV_TYPE_DOMAIN_CTRL Then         IsServer = True      Else         IsServer = False      End If         Else      Debug.Print "Error: " & Err.LastDllError   End If   End Function

See also  How to Avoid Money Transfer Scams  

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist