Results 1 to 4 of 4

Thread: list of sql servers

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Posts
    9
    is it possible to find out all the list of sql servers using vb????

  2. #2
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    I know it's possible cuz I've seen Serge do it...

    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Posts
    9
    but how??? can u or your friend give me a sample code?? pls help

  4. #4
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    It is possible only in NT/2000 environment.
    If you're running under NT or 2000 then you can do this. Add a Listbox (List1), Command Button (Command1) and a Label (Label1):
    VB Code:
    1. Private Declare Function NetServerEnum Lib "Netapi32.dll" (vServername As Any, ByVal lLevel As Long, vBufptr As Any, lPrefmaxlen As Long, lEntriesRead As Long, lTotalEntries As Long, vServerType As Any, ByVal sDomain As String, vResumeHandle As Any) As Long
    2. Private Declare Sub RtlMoveMemory Lib "kernel32" (dest As Any, vSrc As Any, ByVal lSize As Long)
    3. Private Declare Sub lstrcpyW Lib "kernel32" (vDest As Any, ByVal sSrc As Any)
    4. Private Declare Function NetApiBufferFree Lib "Netapi32.dll" (ByVal lpBuffer As Long) As Long
    5. Private Type SERVER_INFO_101
    6.     dw_platform_id As Long
    7.     ptr_name As Long
    8.     dw_ver_major As Long
    9.     dw_ver_minor As Long
    10.     dw_type As Long
    11.     ptr_comment As Long
    12. End Type
    13. Private Const SV_TYPE_SQLSERVER = &H4
    14.  
    15. Private Type OSVERSIONINFO
    16.         dwOSVersionInfoSize As Long
    17.         dwMajorVersion As Long
    18.         dwMinorVersion As Long
    19.         dwBuildNumber As Long
    20.         dwPlatformId As Long
    21.         szCSDVersion As String * 128
    22. End Type
    23. Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
    24. Private Const VER_PLATFORM_WIN32_NT = 2
    25. Private Const VER_PLATFORM_WIN32_WINDOWS = 1
    26. Private Const VER_PLATFORM_WIN32s = 0
    27.  
    28.  
    29. Private Type WKSTA_INFO_101
    30.    wki101_platform_id As Long
    31.    wki101_computername As Long
    32.    wki101_langroup As Long
    33.    wki101_ver_major As Long
    34.    wki101_ver_minor As Long
    35.    wki101_lanroot As Long
    36. End Type
    37.  
    38. Private Type WKSTA_USER_INFO_1
    39.    wkui1_username As Long
    40.    wkui1_logon_domain As Long
    41.    wkui1_logon_server As Long
    42.    wkui1_oth_domains As Long
    43. End Type
    44. Private Declare Function NetWkstaGetInfo Lib "Netapi32" (strServer As Any, ByVal lLevel As Long, pbBuffer As Any) As Long
    45. Private Declare Function NetWkstaUserGetInfo Lib "Netapi32" (reserved As Any, ByVal lLevel As Long, pbBuffer As Any) As Long
    46.  
    47. Function GetDomainName()
    48.     Dim lngRet As Long
    49.     Dim arrByteBuffer(512) As Byte
    50.     Dim i As Integer
    51.     Dim tWK_INFO As WKSTA_INFO_101
    52.     Dim lngWK_Ptr As Long
    53.     Dim tWK_USER As WKSTA_USER_INFO_1
    54.     Dim lngWK_USER_Ptr As Long
    55.     Dim strDomain As String
    56.  
    57.     If IfWinNT Then
    58.         lngRet = NetWkstaGetInfo(ByVal 0&, 101, lngWK_Ptr)
    59.         RtlMoveMemory tWK_INFO, ByVal tWK_INFO, Len(tWK_INFO)
    60.         lngRet = NetWkstaUserGetInfo(ByVal 0&, 1, lngWK_USER_Ptr)
    61.         RtlMoveMemory tWK_USER, ByVal lngWK_USER_Ptr, Len(tWK_USER)
    62.         lstrcpyW arrByteBuffer(0), tWK_USER.wkui1_logon_domain
    63.         'Get Every other byte of the array
    64.         i = 0
    65.         Do While arrByteBuffer(i) <> 0
    66.             strDomain = strDomain & Chr(arrByteBuffer(i))
    67.             i = i + 2
    68.         Loop
    69.         lngRet = NetApiBufferFree(lngWK_USER_Ptr)
    70.  
    71.         GetDomainName = strDomain
    72.     Else
    73.         GetDomainName = ""
    74.     End If
    75. End Function
    76.  
    77. Private Function IfWinNT() As Boolean
    78.     Dim os As OSVERSIONINFO
    79.     Dim lngRet As Long
    80.    
    81.     os.dwOSVersionInfoSize = Len(os)
    82.     lngRet = GetVersionEx(os)
    83.    
    84.     If lngRet <> 0 Then
    85.         Select Case os.dwPlatformId
    86.             Case VER_PLATFORM_WIN32_NT
    87.                 IfWinNT = True
    88.             Case Else
    89.                 IfWinNT = False
    90.         End Select
    91.     End If
    92. End Function
    93.  
    94.  
    95.  
    96. Private Sub Command1_Click()
    97.     Dim lngRet As Long
    98.     Dim Server_Info As Long
    99.     Dim lngEntries As Long
    100.     Dim lngTotal As Long
    101.     Dim lngMax As Long
    102.     Dim varResume As Variant
    103.     Dim tServer_info_101 As SERVER_INFO_101
    104.     Dim strServer As String
    105.     Dim strDomain As String
    106.     Dim lngServerInfo101StructPtr As Long
    107.     Dim lngCount As Long
    108.     Dim i As Long
    109.     Dim arrByteBuffer(512) As Byte
    110.    
    111.    
    112.    
    113.     If Not IfWinNT Then
    114.         MsgBox "You're not running under Window NT/2000."
    115.     End If
    116.    
    117.    
    118.     strDomain = GetDomainName
    119.    
    120.    
    121.     lngRet = NetServerEnum(ByVal 0&, 101, Server_Info, lngMax, _
    122.                             lngEntries, lngTotal, _
    123.                             ByVal SV_TYPE_SQLSERVER, StrConv(strDomain, vbUnicode), varResume)
    124.  
    125.     If lngRet <> 0 Then
    126.         MsgBox "Error Getting SQL Servers."
    127.         Exit Sub
    128.     End If
    129.  
    130.     lngCount = 1
    131.     lngServerInfo101StructPtr = Server_Info
    132.  
    133.     Do While lngCount <= lngTotal
    134.         RtlMoveMemory tServer_info_101, ByVal lngServerInfo101StructPtr, Len(tServer_info_101)
    135.  
    136.         lstrcpyW arrByteBuffer(0), tServer_info_101.ptr_name
    137.  
    138.         i = 0
    139.         Do While arrByteBuffer(i) <> 0
    140.             strServer = strServer & Chr(arrByteBuffer(i))
    141.             i = i + 2
    142.         Loop
    143.        
    144.         If Len(Trim(strServer)) > 0 Then List1.AddItem strServer
    145.        
    146.         lngCount = lngCount + 1
    147.         strServer = ""
    148.         lngServerInfo101StructPtr = lngServerInfo101StructPtr + Len(tServer_info_101)
    149.     Loop
    150.  
    151.     lngRet = NetApiBufferFree(Server_Info)
    152.    
    153.    
    154.     Label1.Caption = "There are " & lngTotal & " SQL Servers in Domain: " & strDomain
    155. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width