"Query Execution Mode" is the default operational mode of the
Log Parser command-line executable.
In this mode, Log Parser is used to execute queries reading input
records from an input format and writing output records to an
output format.
The general syntax of commands in query execution mode
is:
LogParser |
C:\>LogParser -i:IISW3C "SELECT * FROM extend1.log"When an input format is not specified, Log Parser will attempt to select automatically an input format upon inspection of the <from-entity> in the FROM clause. For example, "System" suggests the use of the EVT Input Format, while "ex040302.log" suggests the use of the IISW3C Input Format.
C:\>LogParser -i:IISW3C -iCodepage:932 -iCheckpoint:MyCheckpoint.lpc "SELECT * FROM extend1.log"
C:\>LogParser -i:EVT -binaryFormat:ASC "SELECT * FROM System"Parameter values containing spaces must be enclosed within double-quote characters ("), as in the following example:
C:\>LogParser -i:EVT -stringsSep:"MY SEPARATOR" "SELECT * FROM System"For more information on input format parameters, refer to the Input Format Reference.
C:\>LogParser -o:CSV "SELECT * FROM System"When an output format is not specified, Log Parser will attempt to select automatically an output format upon inspection of the <into-entity> in the INTO clause. For example, "chart.gif" suggests the use of the CHART Output Format, while "MyFile.csv" suggests the use of the CSV Output Format.
C:\>LogParser -o:NAT -rtp:-1 -fileMode:1 "SELECT * FROM System"
C:\>LogParser -o:CSV -tabs:ON "SELECT * FROM System"Parameter values containing spaces must be enclosed within double-quote characters ("), as in the following example:
C:\>LogParser -o:CHART -chartTitle:"Page Hits per Day" "SELECT date, COUNT(*) FROM extend1.log GROUP BY date"For more information on output format parameters, refer to the Output Format Reference.
C:\>LogParser "SELECT * FROM System"Alternatively, a query can be specified through a text file with the "file:" switch, as shown in the next section.
SELECT TimeGenerated, EXTRACT_TOKEN(ResolvedSid, 1, '\\') AS Username -- only the 'username' portion /* We want to retrieve the full user name */ USING RESOLVE_SID(Sid) AS ResolvedSid FROM SecurityThe following example shows how the query is executed, assuming that the query text has been saved to a file named "MyQuery.sql":
C:\>LogParser -i:EVT file:Myquery.sqlQuery text files can include parameters, which are substituted at runtime with user-supplied text or environment variable values.
SELECT EventID FROM %InputEventLog% WHERE SourceName = '%InputSourceName%'The following example command executes the query substituting user-supplied values for the parameters:
C:\>LogParser -i:EVT file:Myquery.sql?InputEventLog=System+InputSourceName=EventLogIf a parameter name or value contains spaces, the name or value must be enclosed within double-quote characters ("), as in the following example:
C:\>LogParser -i:EVT file:Myquery.sql?InputEventLog=System+InputSourceName="Service Control Manager"If the value of a query text file parameter is not supplied by the user, Log Parser will search for the parameter name in the current environment variable set. If an environment variable is found matching the parameter name, its value will be substituted for the parameter; otherwise, the parameter name is left as-is in the query text.
The text of the query can also be specified directly as a
command-line argument, as shown in the previous section.
Commands containing both a query text argument and a "file:" switch
are considered illegal and return an error.
The following example uses the "-queryInfo" switch to display diagnostic information about the specified command:
C:\>LogParser "SELECT TO_UTCTIME(TimeGenerated) AS UTCTimeGenerated, SourceName FROM System WHERE EventID > 20" -queryInfoThe output of this command is:
Query: SELECT TO_UTCTIME([TimeGenerated]) AS UTCTimeGenerated, [SourceName] FROM System WHERE [EventID] > ANY (20) Formats selected: Input format: EVT (Windows Event Log) Output format: NAT (Native Format) Query fields: UTCTimeGenerated (T) SourceName (S)
© 2004 Microsoft Corporation. All rights reserved.