ptrex Posted January 9, 2009 Share Posted January 9, 2009 Accessing WMI using WBEM OdbcThis method shown below accesses the WMI classes using a normal ODBC connection.Prerequisite is that you have the WBEM driver available on your machine.(I think that this is natively installed in all XP Pro machines ?)expandcollapse popupInitialize error handler $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") Const $adPromptComplete = 1 Dim $cnn Dim $rst $cnn = ObjCreate("ADODB.Connection") $rst = ObjCreate("ADODB.Recordset") $dtmConvertedDate = ObjCreate("WbemScripting.SWbemDateTime") With $cnn .Provider = "MSDASQL.1" .Open ('Provider=MSDASQL.1;Extended Properties="DSN=WBEM Source;DBQ=root\CIMV2;SERVER=;UIDPWDDEFINED=;UID=;PWD=;SYSPROPS=FALSE;NAMESPACES={root\CIMV2,deep}"') ConsoleWrite($cnn.ConnectionString & @LF) EndWith With $rst .ActiveConnection = $cnn .Source = ("SELECT * FROM Win32_NTLogEvent Where Logfile = 'Application' and RecordNumber > 20800'") ; ConsoleWrite(.Source & @CRLF) .Open EndWith While not $rst.EOF For $i = 0 To $rst.Fields.Count - 1 ConsoleWrite($i & " " & $rst.Fields($i).Name & " " & $rst.Fields($i).Value & @CR ) Next $rst.MoveNext ConsoleWrite(@CR) WEnd $cnn.Close $rst.ActiveConnection.Close ;This is custom error handler Func MyErrFunc() $HexNumber=hex($oMyError.number,8) Msgbox(0,"COM Test","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & $HexNumber & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) SetError(1) ; to check for after this function returns EndfuncImportant : Change the Query for you spesific needs, when it fails.In some case this can open opportunities, in other cases it can be a limitation using this method.Anyhow, here you get an other scripting technique which you might use (or not ?!)In combination with my prior PivotTable script, this is a nice complementory scripting approach. To build multidimentions data views of WMI classes.Regards,ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
Michel Claveau Posted January 10, 2009 Share Posted January 10, 2009 Hi!Good idea.Note: for install WMI ODBC, see: http://msdn.microsoft.com/en-us/library/aa390889(VS.85).aspx@-salutations-- Michel Claveau Link to comment Share on other sites More sharing options...
ptrex Posted January 10, 2009 Author Share Posted January 10, 2009 @Michel Claveau Your welcome. Au revoir !! ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
Paulchen Posted January 11, 2009 Share Posted January 11, 2009 Be careful, the WMI ODBC are not on all OS supportet. ...The WMI ODBC Adapter is not available in Windows Server 2003. When you upgrade to Windows Server 2003 from Windows 2000 Server, the WMI ODBC Adapter is not removed if already present on a computer. The ODBC Adapter may be unsupported in subsequent versions of Windows. ...http://msdn.microsoft.com/en-us/library/aa392726(VS.85).aspx Link to comment Share on other sites More sharing options...
ptrex Posted January 11, 2009 Author Share Posted January 11, 2009 @Paulchen,2 ways to overcome this problem.1. The WBEM Driver can be installed saperately from the W2K CD value added. Even on a W2003 server.2. Copy the WBEM DLL to a W2003 server and use the ODBC API to access the driver in AU3. ODBC APIDon't give up so easily PS : I don't know if it is available on a Vista OS ?Regards,ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
Michel Claveau Posted January 12, 2009 Share Posted January 12, 2009 Hi!I don't know if it is available on a Vista OS ?No.In Vista, Windows-2008 and Seven, MDAC is changed to Windows-DAC. But MDAC & Windows-DAC are similary. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now