'==========================================================================
'
' VBScript:  AUTHOR: Ed WIlson, msft,  9/23/2005
'
' NAME: <QueryExcelUsingADO.vbs>
'ver.2.0 added extra variables, and cleaned up code
' COMMENT: Key concepts are listed below:
'1. Uses Microsoft.Jet.Oledb.4.0 provider. Must specify DataSource, and extended properties.
'2. The worksheet is supplied in [] with a trailing $
'3. First row is column headers, and is the field name. 
'4. kb257819 is a good reference
'==========================================================================

Option Explicit    	     ' is used to force the scripter to declare variables
'On Error Resume Next ' is used to tell vbscript to go to the next line if it encounters an Error

Dim strQuery
Dim objConnection
Dim objCommand
Dim objRecordSet
Dim strProvider 'the name of the provider
Dim strDataSource
Dim strExtend
Dim strFileName

strProvider = "Provider=Microsoft.Jet.OLEDB.4.0"
strExtend = "Extended Properties=Excel 8.0"
strFileName = funfix("WMIprovidersXP.xls")  'Ensure script can find this file.
strDataSource = "Data Source =" & strFileName

strQuery = "Select * from [CIMV2$]" '[] required for sheet name of excel. Must have the $

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Open strProvider & ";" & strDataSource &";" & strExtend
objCommand.ActiveConnection = objConnection
objCommand.CommandText = strQuery
Set objRecordSet = objCommand.Execute

Do Until objRecordSet.EOF
    Wscript.Echo objRecordSet.Fields("Class Name") 'column name.
    objRecordSet.MoveNext
Loop

objConnection.Close


' *** function below ***

Function funfix (strIN)
funfix = "'" & strIN & "'"
End Function