'*************************************************************************
' $ScriptName: "GetSqlDriverName" $
'
' Purpose: This script is used to get SQL Driver name.
'
' $File: GetSqlDriverName.vbs $
'*************************************************************************
Option Explicit
Function GetSqlDriverName
Dim oAPI1, oReg
Const HKEY_LOCAL_MACHINE = &H80000002
Dim strComputer, strDriverPath, strKeyPath, intValue, strValueName,arrSubKeys,oSubkey,strNewKeyPath,intDotIndex
strComputer = "."
strDriverPath="SQLOLEDB"
Set oReg=GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\ODBC\ODBCINST.INI"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each oSubkey In arrSubKeys
intValue = InStr(oSubkey, "SQL Server Native Client")
if intValue <> 0 Then
strValueName = "Driver"
strNewKeyPath = strKeyPath&"\"&oSubkey
oReg.GetStringValue HKEY_LOCAL_MACHINE, strNewKeyPath, strValueName , strDriverPath
strDriverPath = Mid (strDriverPath, InStrRev(strDriverPath, "\")+1)
intDotIndex = InStr(strDriverPath, ".")
strDriverPath = Left(strDriverPath , intDotIndex-1)
end if
Next
GetSqlDriverName = strDriverPath
End Function
'*************************************************************************
' ScriptName: SQLBrokerAvailibilityQuery.vbs
'
' Purpose - Populate properties of DW Management Server
'
' Parameters - 0 - discovery id
' 1 - Target managed entity id
' 2 - Host Computer Principal Name
' 3 - Version
'*************************************************************************
SetLocale("en-us")
Dim sourceId,managedEntityId,oAPI,strKeyPath,principalName, version, oBag
Set oAPI = CreateObject("MOM.ScriptAPI")
principalName = WScript.Arguments(0)
version = WScript.Arguments(1)
'Call oAPI.LogScriptEvent("SQLBrokerAvailibilityQuery.vbs", 3000, 4, "Starting query of SQL Broker availibility")
Set oBag = oAPI.CreatePropertyBag()
Dim oReg, iResult
Set oReg = GetObject("winmgmts:\\" & principalName & "\root\default:StdRegProv")
If Err <> 0 Then
Call oAPI.LogScriptEvent("SQLBrokerAvailibilityQuery.vbs", 3000, 4, "Unable to bind to WMI registry provider on " & principalName & ". Terminating Script.")
Call oAPI.Return(oBag)
WScript.Quit
End if
Const HKLM = &H80000002
If version = "2010" or version = "2012" then
Dim strKeyRoot, strDatabaseServerName, strDatabaseName, ibrokerEnabled
ibrokerEnabled = 0
strKeyRoot = "SOFTWARE\Microsoft\System Center\2010\Common\Database"
iResult = oReg.GetStringValue(HKLM, strKeyRoot, "DatabaseServerName", strDatabaseServerName)
If iResult = 0 then
iResult = oReg.GetStringValue(HKLM, strKeyRoot, "DatabaseName", strDatabaseName)
If iResult = 0 then
'Call oAPI.LogScriptEvent("SQLBrokerAvailibilityQuery.vbs", 3000, 4, "Recovered Registry keys from " & principalName )
Dim connectionString, cnADOConnection, oResults,oQuery, strDriverName
strDriverName = GetSqlDriverName
connectionString = "Provider=" & strDriverName & ";Server=" & strDatabaseServerName & ";Integrated Security=SSPI;Initial Catalog=" & strDatabaseName
Set cnADOConnection = CreateObject("ADODB.Connection")
cnADOConnection.Open connectionString
cnADOConnection.CommandTimeout = 300
oQuery = "SELECT cast(is_broker_enabled as int) As BrokerEnabled FROM sys.databases WHERE name = DB_Name()"
oResults = CreateObject("ADODB.Recordset")
Set oResults = cnADOConnection.Execute(oQuery)
If oResults.State <> 0 Then
Do Until oResults.EOF
iBrokerEnabled = oResults.Fields("BrokerEnabled")
oResults.MoveNext
Loop
End If
If oResults.State <> 0 Then
oResults.Close
End If
cnADOConnection.Close
End If
End If
If iBrokerEnabled = 1 then
Call oBag.AddValue("BrokerEnabled", 1)
Else
Call oBag.AddValue("BrokerEnabled", 0)
End if
End If