• Hi:

    this example them can be of utility

    Function BDSql(strComputer)

    Dim strSql 'Used to hold the SQL Query

    Dim objConn 'Used for the Connection object

    Dim objRst 'Used for the Recordset object

    Dim fecha

    SQLDMOSecurity_Integrated  = 1

    SQLDMOSecurity_Mixed         = 2

    SQLDMOSecurity_Normal       = 0

    SQLDMOSecurity_Unknown   = 9

    strDBServerName = StrComputer

    'On Error Resume Next

    Set objConn = CreateObject("ADODB.Connection")

    objConn.Open "Provider=sqloledb;" & "Data Source=ccstnoc;" & "Initial Catalog=sistemanoc;" & "User Id=cuenta;" & "Password=password"

    Set objSQLServer = CreateObject("SQLDMO.SQLServer")

    objSQLServer.LoginSecure = True

    objSQLServer.Connect strDBServerName

    If Err.Number <> 0 Then

     EXPLANATION = "Proceso termino con problemas"

     BDSql = False

    End If

    Set colDatabases = objSQLServer.Databases

    'WScript.echo "SQL Version String: " & objSQLServer.VersionString

    Select Case objSQLServer.ServerLoginMode(strDBServerName)

       Case SQLDMOSecurity_Integrated

          Login = "Login Mode: Allow Windows Authentication only."

       Case SQLDMOSecurity_Mixed

          Login = "Login Mode: Allow Windows Authentication or SQL Server Authentication."

       Case SQLDMOSecurity_Normal

          Login =  "Login Mode: Allow SQL Server Authentication only."

       Case SQLDMOSecurity_Unknown

          Login = "Login Mode: Security type unknown."

    End Select

    'strSql3 = "delete from SqlServer where nombre = '" & strDBServerName & "'"

    'Set objRst3 = objConn.Execute(strSql3)

    For Each objDatabase In colDatabases

       'WScript.Echo objDatabase.Name

       strDBName = objDatabase.Name

       Set objDB = objSQLServer.Databases(strDBName)

       'WScript.Echo "Total Size of Data File + Transaction Log of DB " & strDBName & ": " & objDB.Size & "(MB)"

       'WScript.echo "Space Left (Data File + Transaction Log) for DB " & strDBName & ": " & objDB.SpaceAvailableInMB & "(MB)"

     

       strSql3 = "insert into SqlServer(Nombre, VersionSQL, BaseDatos, TamanoBD, EspacioLibre, Login, fecha ) values('" & strDBServerName & "', '" & objSQLServer.VersionString & "', '" & strDBName & "', '" & objDB.Size & "', '" & objDB.SpaceAvailableInMB & "', '" & Login & "', '" & Date & "')"

       Set objRst3 = objConn.Execute(strSql3)

    Next

    BDSql = True

    EXPLANATION = "proceso termino ok."

    End Function