WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

LogParser

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

LogParser User Demo 2

 Keywords: LogParser  MSUtil.LogQuery

This script requires the use of two files: LogParserBatchComDemo.wbt and QFE.wsc


LogParserBatchComDemo.wbt

;Microsoft LogParser 2.2 - 'roll your own' - COM Demo
;
;This script demonstrates using a custom .wsc file to
;parse data that is not one of LogParser's standard formats.
;By use of GetObject(), WB is able to eliminate the need to
;have the .wsc file physically registered on the PC.
;
;This script uses BatchExecute() with XML output
;
;the .wsc file is specific to obtaining WMI records releated to
;hotfixes on the PC
;
;To download version 2.2
;http://www.microsoft.com/technet/scriptcenter/tools/logparser/default.mspx
;
;User guide
;http://www.vogtland.ws/Sharepoint%20Reference%20Library/LogParser%202.2%20User%20Guide.pdf
;Stan Littlefield, January 22, 2006
;//////////////////////////////////////////////////////////////////////////////////////


;initial setup
cWsc = StrCat(DirScript(),"QFE.wsc")
If ! FileExist(cWsc) Then Exit
cWsc = StrCat("script:",cWsc)
cMsg = "Unable To Create CSV from Query"
cXML = StrCat(DirScript(),"comdemo.xml")
cSQL = "SELECT * INTO %cXML% FROM . WHERE QFE NOT LIKE '%%File%%'"  ;this is the WMI query
                                                                    ;to filter records
;//////////////////////////////////////////////////////////////////////////////////////

BoxOpen("Please Wait...",StrCat("Processing LogParser Query",@CRLF,cSQL) )
If FileExist(cXML) Then FileDelete(cXML)
oLog = CreateObject("MSUtil.LogQuery")
oInput = GetObject(cWsc)
oInput.ExtendedFields = "ON"
oOut = CreateObject("MSUtil.LogQuery.XMLOutputFormat.1")
oRS = oLog.ExecuteBatch(cSQL, oInput, oOut )
If oLog.lastError <> 0
   cErrors = StrCat("Errors:",@CRLF)
   ForEach strMessage In oLog.errorMessages
        cErrors=StrCat(cErrors,strMessage,@CRLF)
   Next
   Message("Error Report",cErrors)
EndIf
:End
oInput=0
oOut=0
oOut=0
oLog=0
If FileExist(cXML) Then cMsg=StrCat(cXML," created from query")
BoxText(cMsg)
TimeDelay(2)
Exit
;//////////////////////////////////////////////////////////////////////////////////////


QFE.wsc

<?xml Version="1.0" ?>
- <component>
  <?component error="true" Debug="true" ?>
  <registration progid="MSUtil.LogQuery.Sample.QFE" classid="{275926B8-2387-4201-ABC3-B8473D7AA677}" description="QFE Input Format" remotable="true" Version="1.00" />
- <public>
- <method name="OpenInput">
  <parameter name="strComputerName" />
  </method>
  <method name="GetFieldCount" />
- <method name="GetFieldName">
  <parameter name="nFieldIndex" />
  </method>
- <method name="GetFieldType">
  <parameter name="nFieldIndex" />
  </method>
  <method name="ReadRecord" />
- <method name="GetValue">
  <parameter name="nFieldIndex" />
  </method>
- <method name="CloseInput">
  <parameter name="bAbort" />
  </method>
- <property name="ExtendedFields">
  <put />
  </property>
  </public>
- <script language="VBScript">
- <![CDATA[

Dim m_objQFEArray
Dim m_nIndex
Dim m_bExtendedFields

m_bExtendedFields = False

Function OpenInput(strComputerName)

	Dim objWMIService
	Dim objQFEs
	Dim nLength
	If isnull(strComputerName) or Len(strComputerName) = 0 Then
      strComputerName = "."
	End If
	' Query for all the QFE's on the specified machine
	Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputerName & "\root\cimv2")
	Set objQFEs = objWMIService.ExecQuery ("Select * from Win32_QuickFixEngineering")

	' Store in array
	m_objQFEArray = Array()
	For Each objQFE In objQFEs
		ReDim Preserve m_objQFEArray( UBound(m_objQFEArray) + 1 )
		Set m_objQFEArray( UBound(m_objQFEArray) ) = objQFE
	Next

	m_nIndex = LBound(m_objQFEArray)

End Function



Function GetFieldCount()

	' This Input Format returns 4 or 6 fields
	If m_bExtendedFields = True Then
		GetFieldCount = 6
	Else
		GetFieldCount = 4
	End If

End Function



Function GetFieldName(nFieldIndex)

	Select Case nFieldIndex
		Case 0 
			GetFieldName = "QFE"
		Case 1
			GetFieldName = "Description"
		Case 2
			GetFieldName = "InstallDate"
		Case 3
			GetFieldName = "InstalledBy"
		Case 4
			GetFieldName = "Comments"
		Case 5
			GetFieldName = "SP"
	End Select

End Function

Function GetFieldType(nFieldIndex)

	Select Case nFieldIndex
		Case 0 
			' String
			GetFieldType = 3
		Case 1
			' String
			GetFieldType = 3
		Case 2
			' Timestamp
			GetFieldType = 4
		Case 3
			' String
			GetFieldType = 3
		Case 4
			' String
			GetFieldType = 3
		Case 5
			' String
			GetFieldType = 3

	End Select

End Function



Function ReadRecord()

	If m_nIndex >= UBound(m_objQFEArray) Then
		' Enumeration terminated
		ReadRecord = False
	Else
		'Advance
		m_nIndex = m_nIndex + 1
		ReadRecord = True
	End If

End Function



Function GetValue(nFieldIndex)

	Select Case nFieldIndex
		Case 0 
			' QFE
			GetValue = m_objQFEArray(m_nIndex).HotFixID
		Case 1
			' Description
			GetValue = m_objQFEArray(m_nIndex).Description
		Case 2
			' InstallDate
			GetValue = m_objQFEArray(m_nIndex).InstallDate
		Case 3
			' InstalledBy
			GetValue = m_objQFEArray(m_nIndex).InstalledBy
		Case 4
			' Comments
			GetValue = m_objQFEArray(m_nIndex).FixComments
		Case 5
			' SP
			GetValue = m_objQFEArray(m_nIndex).ServicePackInEffect

	End Select	

End Function


Function CloseInput(bAbort)

	m_objQFEArray = Array()

End Function


Function put_ExtendedFields(strValue)

	If UCase(strValue) = "ON" Then
		m_bExtendedFields = True
	Else
		m_bExtendedFields = False
	End If

End Function

 ]]>
  </script>
  </component>



Article ID:   W18085
Filename:   LogParser User Demo 2.txt
File Created: 2009:03:26:09:07:52
Last Updated: 2009:03:26:09:07:52