nslookup.exe sc.exe. SQL Server , nslookup . , SQL Server 8 1 . , . , , (, [ShellWait, Qt, PassThru, LogError] ):
UPDATE: , dmaruca clsRunApp ( ) , Philippe . , , . , :
Function SQLServerDBExists(ComputerName As String, DbName As String) As Boolean
Const LocalHost = "127.0.0.1"
Dim Result As String, RunApp As New clsRunApp
On Error GoTo Err_SQLServerDBExists
If ComputerName <> LocalHost And _
ComputerName <> "." And _
ComputerName <> Environ("COMPUTERNAME") Then
'Check for existence of the server using Name Server Lookup'
Result = RunApp.RunAppWait_CaptureOutput("nslookup " & ComputerName)
If InStr(Result, "Non-existent domain") Or _
InStr(Result, "Default servers are not available") Then
SQLServerDBExists = False
GoTo Exit_SQLServerDBExists
End If
End If
Result = RunApp.RunAppWait_CaptureOutput("sc \\" & ComputerName & " qdescription MSSQLSERVER")
If InStr(Result, "SUCCESS") Then
With PassThru("SELECT Name FROM sysdatabases " & _
"WHERE Name='" & DbName & "'", "master", ComputerName)
SQLServerDBExists = (Not .EOF)
End With
End If
Exit_SQLServerDBExists:
Exit Function
Err_SQLServerDBExists:
LogError Err.Number, Err.Description, "SQLServerDBExists", "AttachToSQL"
Resume Exit_SQLServerDBExists
End Function
. , Environ ( "COMPUTERNAME" ) 100% , , . , .