Skip to content

Commit

Permalink
WMI Namespace for SQL 2012 added
Browse files Browse the repository at this point in the history
  • Loading branch information
red55 committed Dec 13, 2013
1 parent be42041 commit 0b5b46d
Showing 1 changed file with 25 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
' OCSINVENTORY-NG
' Web : http://www.ocsinventory-ng.org
'
' Liste les bases de données SQL Server du poste
' 4 données sont remontées :
' Liste les bases de donn�es SQL Server du poste
' 4 donn�es sont remont�es :
' - strSQLName : Nom long du produit SQL Server
' Par exple : "Microsoft SQL Server 2008 R2"
' - strServiceName : Nom de l'instance
' Par exple : "MSSQLSERVER"
' - strEdition : Edition.
' Par exple : "Enterprise Edition (64-bit)"
' - strVersion : Version "chiffrée".
' - strVersion : Version "chiffr�e".
' Par exple : "8.00.194"
'
' Auteur : Sylvie Grimonpont
Expand All @@ -24,7 +24,7 @@

On Error Resume Next

'Déclaration des constantes
'D�claration des constantes
Const DblQuote = """"
Const ForReading = 1
Const HKEY_LOCAL_MACHINE = &H80000002
Expand All @@ -36,14 +36,14 @@ if WScript.Arguments.Count = 0 then
WScript.Echo "Missing parameters"
end if

' Spécificités SQL 2000
' RegExp pour récupération de l'édition dans un fichier ERRORLOG
' Sp�cificit�s SQL 2000
' RegExp pour r�cup�ration de l'�dition dans un fichier ERRORLOG
Set regexpEdition = New RegExp
regexpEdition.IgnoreCase = True
regexpEdition.Global = True
regexpEdition.Pattern = "^.*dition"

' RegExp pour récupération de la version dans un fichier ERRORLOG
' RegExp pour r�cup�ration de la version dans un fichier ERRORLOG
Set regexpVersion = New RegExp
regexpVersion.IgnoreCase = True
regexpVersion.Global = True
Expand All @@ -61,7 +61,7 @@ If Err = 0 Then
If Err = 0 Then
If colServices.count > 0 Then
If Err = 0 Then
'Wscript.Echo "SQL Server trouvé !"
'Wscript.Echo "SQL Server trouv� !"
For Each objService in colServices
' ServiceName
strServiceName = objService.Name
Expand Down Expand Up @@ -102,9 +102,10 @@ If Err = 0 Then

' Positionne la classe WMI SqlServer en fonction de la version du fichier sqlservr.exe
If strSQLFileVersion = 90 Then strWMIsql = "ComputerManagement"
If strSQLFileVersion > 90 Then strWMIsql = "ComputerManagement10"
If strSQLFileVersion = 100 Then strWMIsql = "ComputerManagement10"
If strSQLFileVersion = 110 Then strWMIsql = "ComputerManagement11"

' Recherche la version et l'édition de la base SQL via la classe WMI SqlServer si disponible
' Recherche la version et l'�dition de la base SQL via la classe WMI SqlServer si disponible
If (strWMIsql <> "") Then
' Si on a eu une erreur entre temps, on efface
Err.Clear
Expand All @@ -124,7 +125,7 @@ If Err = 0 Then
End If
End If

' Si on n'a pas pu determiner la version et l'édition à partir de la classe WMI (cas SQL Server 2000), on essaie de la déterminer à partir du fichier ERRORLOG (si en local)
' Si on n'a pas pu determiner la version et l'�dition � partir de la classe WMI (cas SQL Server 2000), on essaie de la d�terminer � partir du fichier ERRORLOG (si en local)
If (((strWMIsql= "") Or (strVersion = "") Or (strEdition = "")) And (strSourceServer = ".")) Then
' On ne trappe plus les erreurs...
On Error Goto 0
Expand All @@ -136,14 +137,14 @@ If Err = 0 Then
For I=0 To UBound(arrValueNames)
If arrValueTypes(I) = REG_SZ Then
objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strMSSQLServerRegKey,arrValueNames(I),strValue
' Dans HKLMSOFTWARE\Microsoft\MSSQLServer\MSSQLServer\Parameters, le paramètre qui commence par "-e" définie le path de ERRORLOG
' Dans HKLMSOFTWARE\Microsoft\MSSQLServer\MSSQLServer\Parameters, le param�tre qui commence par "-e" d�finie le path de ERRORLOG
If Left(strValue,2) = "-e" Then
strErrorlogPath = Mid(strValue,3)
End If
End If
Next

' Si on a trouvé le chemin du fichier ERRORLOG dans la base de registre, on essaie de lire le fichier en question
' Si on a trouv� le chemin du fichier ERRORLOG dans la base de registre, on essaie de lire le fichier en question
If strErrorlogPath <> "" Then
' Teste l'existence du fichier
Set objFSO = CreateObject("Scripting.FileSystemObject")
Expand All @@ -166,13 +167,13 @@ If Err = 0 Then
strError = "Le fichier " & strErrorlogPath & " n'existe pas"
End If
Else
strError = "Information sur fichier ERRORLOG non trouvée en base de registre"
strError = "Information sur fichier ERRORLOG non trouv�e en base de registre"
End If
Else
strError = "Information sur fichier ERRORLOG non trouvée en base de registre"
strError = "Information sur fichier ERRORLOG non trouv�e en base de registre"
End If
End If
' Récupération du nom SQL Server
' R�cup�ration du nom SQL Server
If Left(strVersion,3) = "6.5" Then
strSQLName = "Microsoft SQL Server 6.5"
ElseIf Left(strVersion,1) = "7" Then
Expand All @@ -191,13 +192,13 @@ If Err = 0 Then
strSQLName = "Microsoft SQL Server"
End if

' Ecrit les données de sortie
' Ecrit les donn�es de sortie

' Les données disponibles sont :
' Les donn�es disponibles sont :
' - strSQLName : Nom long du produit SQL Server
' - strServiceName : Nom de l'instance
' - strEdition : Edition. Par exple : Enterprise Edition (64-bit) / Express Edition
' - strVersion : Version "chiffrée". Par exemple : 8.00.194 / 10.50.1600.1
' - strVersion : Version "chiffr�e". Par exemple : 8.00.194 / 10.50.1600.1
Select Case Arg(0)
Case "NAME"
Wscript.Echo strSQLName
Expand Down Expand Up @@ -228,7 +229,7 @@ If Err = 0 Then
End If
Else
On Error Goto 0
'Wscript.Echo "Aucun SQL Server trouvé !"
'Wscript.Echo "Aucun SQL Server trouv� !"
End if
Else
WriteError()
Expand All @@ -244,7 +245,7 @@ WScript.Quit
Sub WriteError()
strError = "Erreur " & Err.Number & " - " & Err.Description

' ' On écrit l'erreur dans le fichier
' ' On �crit l'erreur dans le fichier

Err.Clear
End Sub
Expand All @@ -270,7 +271,7 @@ Sub ReadErrorLog (strFilePath)
For i = 1 To 4
strErrorlogText = objTextFile.Readline

' La version se trouve sur la première ligne
' La version se trouve sur la premi�re ligne
If i = 1 Then
Set versions = regexpVersion.Execute(strErrorlogText)
For Each version In versions
Expand All @@ -282,7 +283,7 @@ Sub ReadErrorLog (strFilePath)
If strVersion="" Then strVersion = "Errolog"
End If

' L'édition se trouve sur la quatrième ligne
' L'�dition se trouve sur la quatri�me ligne
If i = 4 Then
strEdition = strErrorlogText
Set editions = regexpEdition.Execute(strErrorlogText)
Expand All @@ -295,4 +296,4 @@ Sub ReadErrorLog (strFilePath)

Next
objTextFile.Close
End Sub
End Sub

0 comments on commit 0b5b46d

Please sign in to comment.