I use the following code to display all the SQL servers on the network:

VB Code:
  1. Option Explicit
  2.  
  3. Private Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long
  4.  
  5. Private Declare Function NetServerEnum Lib "netapi32" ( _
  6.        strServername As Any, _
  7.        ByVal level As Long, _
  8.        bufptr As Long, _
  9.        ByVal prefmaxlen As Long, _
  10.        entriesread As Long, _
  11.        totalentries As Long, _
  12.        ByVal servertype As Long, _
  13.        strDomain As Any, _
  14.        resumehandle As Long) As Long
  15.  
  16.  
  17. Private Declare Function NetApiBufferFree Lib "Netapi32.dll" _
  18. (ByVal lpBuffer As Long) As Long
  19.  
  20. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
  21. (Destination As Any, Source As Any, ByVal Length As Long)
  22.  
  23. Private Const SV_TYPE_SERVER As Long = &H2
  24. Private Const SV_TYPE_SQLSERVER As Long = &H4
  25.  
  26. Private Type SV_100
  27.  platform As Long
  28.  Name As Long
  29. End Type
  30.  
  31.  
  32. Public DEBUGMODE As Boolean
  33.  
  34.  
  35. Public Function GetSQLServers(DomainName As String) As String()
  36.    Dim l As Long
  37.    Dim entriesread As Long
  38.    Dim totalentries As Long
  39.    Dim hREsume As Long
  40.    Dim bufptr As Long
  41.    Dim level As Long
  42.    Dim prefmaxlen As Long
  43.    Dim lType As Long
  44.    Dim Domain() As Byte
  45.    Dim i As Long
  46.    Dim sv100 As SV_100
  47.    Dim Servers() As String
  48.  
  49.    level = 100
  50.    prefmaxlen = -1
  51.  
  52.    lType = SV_TYPE_SQLSERVER
  53.    Domain = DomainName & vbNullChar
  54.    l = NetServerEnum(ByVal 0&, _
  55.            level, _
  56.            bufptr, _
  57.            prefmaxlen, _
  58.            entriesread, _
  59.            totalentries, _
  60.            lType, _
  61.            Domain(0), _
  62.            hREsume)
  63.  
  64.    If l = 0 Or l = 234& Then
  65.        ReDim Servers(entriesread - 1)
  66.        For i = 0 To entriesread - 1
  67.            CopyMemory sv100, ByVal bufptr, Len(sv100)
  68.            Servers(i) = Pointer2stringw(sv100.Name)
  69.            bufptr = bufptr + Len(sv100)
  70.        Next i
  71.    Else
  72.        ReDim Servers(0)
  73.        Servers(0) = "N/A"
  74.    End If
  75.    NetApiBufferFree bufptr
  76.    GetSQLServers = Servers
  77. End Function
  78.  
  79. Private Function Pointer2stringw(ByVal l As Long) As String
  80.    Dim buffer() As Byte
  81.    Dim nLen As Long
  82.    '
  83.    nLen = lstrlenW(l) * 2
  84.    If nLen Then
  85.        ReDim buffer(0 To (nLen - 1)) As Byte
  86.        CopyMemory buffer(0), ByVal l, nLen
  87.        Pointer2stringw = buffer
  88.    End If
  89. End Function

However, if I stop running the server on my machine and then resume it again, it won't show up again. Any ideas why?