1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
/* Connexion SQL */
Const adOpenStatic = 3
Const adLockOptimistic = 3
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
Dim CS, TSQL
CS = "Provider=SQLOLEDB;Data Source=NomServeurSQL;" & _
"Trusted_Connection=Yes;Initial Catalog=NomDB;" & _
"User ID=Utilisateur;"
objConnection.Open CS
/* Gestion WMI*/
Dim Computer, WSQL
Dim Cpt
Computer = "NomMachine"
WSQL = "SELECT * FROM __InstanceModificationEvent WITHIN 5 WHERE TargetInstance ISA 'Win32_PerfFormattedData_PerfOS_Processor' AND TargetInstance.name = '_Total'"
Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2").ExecNotificationQuery(WSQL)
Cpt = 1
Do While Cpt <= 10 /* Limitation à 10 occurrences uniquement pour le test) */
Set oEvent = oWMI.NextEvent()
TSQL = "INSERT INTO dbo.Test (NomMachine, PourcentageProcesseur) " &_
"VALUES (" & "'" & Computer & "'," & oEvent.TargetInstance.PercentProcessorTime & ")"
objRecordSet.Open TSQL, objConnection, adOpenStatic, adLockOptimistic
Cpt = Cpt+1
Loop
Set objRecordSet = Nothing
Set objConnection = Nothing |
Partager