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

Samples from Users
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

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

LogParser


Log Parser is a very powerful, versatile tool that provides universal query access to text-based data, such as log files, XML files, and CSV files, as well as key data sources on the Microsoft Windows operating system, such as the event log, the registry, the file system, and the Active Directory directory service.

Reference: http://support.microsoft.com/kb/910447

LogParser user manual in PDF: http://www.vogtland.ws/Sharepoint%20Reference%20Library/LogParser%202.2%20User%20Guide.pdf it is 570 pages, and very thorough.

In addition to the excellent input formats LogParser has built in, they offer an extensible API to build custom formats. These can be created with C++, C# or with a lowly .wsc file. I liked the .wsc concept, having worked with it in WB. Of course, the docs say the .wsc HAS to be registered, but I was thinking and hoping that GetObject() could suffice, and therefore WB scripts could parse virtually anything w/Logparser in about 3-4 lines of generic script code.

Bubble was a little burst... LogParser's ExecuteBatch() method just gave errors. Then after re-reading their help file, I found there were methods and properties built in to their COM extension and I could obtain output with the Execute() method.

The attached script will output Hotfixes from WMI via a script and the LogParser Sample qbf.wsc file.

LogParser is an amazing tool for scripting!


LOGPARSERCOMDEMO.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.
;
;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"
cCSV = StrCat(DirScript(),"comdemo.csv")
cSQL = 'SELECT * FROM .'  ;this is the WMI query for local machine
;//////////////////////////////////////////////////////////////////////////////////////

BoxOpen("Please Wait...",StrCat("Processing LogParser Query",@CRLF,cSQL) )
If FileExist(cCSV) Then FileDelete(cCSV)
oLog = CreateObject("MSUtil.LogQuery")
oInput = GetObject(cWsc)
oInput.ExtendedFields = "ON"
oRS = oLog.Execute(cSQL, oInput )
If oLog.lastError <> 0
   cErrors = StrCat("Errors:",@CRLF)
   ForEach strMessage In oLog.errorMessages
        cErrors=StrCat(cErrors,strMessage,@CRLF)
   Next
   Message("Error Report",cErrors)
EndIf

cTxt=""
n=oRS.GetColumnCount()
For i=0 To (n-1)
   cTxt = cTxt:oRS.GetColumnName(i):","
Next
cTxt= StrSub(cTxt,1,StrLen(cTxt)-1):@CRLF
While ! oRS.atEnd()
   oRec = oRS.GetRecord()
   If oRec.GetValue(0) == "File 1"
      oRS.MoveNext()
      Continue
   EndIf
   cTxt = cTxt:oRec.toNativeString( "," ):@CRLF
   oRS.MoveNext()
EndWhile
oRec=0
oRS.Close()
FilePut(cCSV,cTxt)

:End
oRS=0
oInput=0
oOut=0
oLog=0
If FileExist(cCSV) Then cMsg=StrCat(cCSV," 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:   W17229
File Created: 2007:07:05:12:49:08
Last Updated: 2007:07:05:12:49:08