Всем привет!
Вот сижу мучаюсь.... есть задача найти все доступные MSSQL-сервера в сети.
В нете нашел вот такой пример
Но переделать его под скрипт не получается
Вот сижу мучаюсь.... есть задача найти все доступные MSSQL-сервера в сети.
В нете нашел вот такой пример
Код:
Public Function AvailableSQLServers() As String()
'***********************************************
'PURPOSE: Returns array list name of all SQL Servers
' on the network that are visible to the
' machine
'
'RETURNS: String array containing names of all
' available SQL Servers (or an array with one
' element containing empty string if no
' SQL Servers are available/visible)
'REQUIRES: Reference to Microsoft SQLDMO object library
' VB6 Because array is returned
' Assumes Option Base is not set to 1
' If you don't have VB6, and/or Option Base 1
' is set, it should not be very hard to modify
' this code for you own purposes
'EXAMPLE:
'Dim sServers() As String
'Dim iCtr As Integer
'sServers = AvailableSQLServers
'If sServers(0) = "" Then
' MsgBox "No SQL Servers Available"
'Else
' For iCtr = 0 To UBound(sServers)
' Debug.Print sServers(iCtr)
' Next
'End If
'***********************************************
Dim oServer As New SQLDMO.Application
Dim oNameList As SQLDMO.NameList
Dim iElement As Integer
Dim sAns() As String
Dim lCtr As Long, lCount As Long
On Error GoTo ErrorHandler
ReDim sAns(0) As String
Set oNameList = oServer.ListAvailableSQLServers
With oNameList
lCount = .Count
If lCount > 0 Then
For lCtr = 1 To .Count
iElement = IIf(sAns(0) = "", 0, UBound(sAns) + 1)
ReDim Preserve sAns(iElement) As String
sAns(iElement) = oNameList.Item(lCtr)
Next
End If
End With
AvailableSQLServers = sAns
Exit Function
ErrorHandler:
'Return array with one empty element on error
ReDim sAns(0) As String
AvailableSQLServers = sAns
End Function