<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.iis.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:cs="http://blogs.iis.net/"><channel><title>Search results matching tag 'logparser Documentation'</title><link>http://forums.iis.net/search/SearchResults.aspx?o=DateDescending&amp;tag=logparser+Documentation&amp;orTags=0</link><description>Search results matching tag 'logparser Documentation'</description><dc:language>en-US</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>How to now the members of local Administrators group in Windows 2003</title><link>http://forums.iis.net/p/1158834/1908561.aspx#1908561</link><pubDate>Mon, 29 Jun 2009 12:15:17 GMT</pubDate><guid isPermaLink="false">50bcf3b4-f6fe-4638-adff-0c150e922e99:1908561</guid><dc:creator>gsiqadm</dc:creator><cs:applicationKey>general_discussion-51</cs:applicationKey><description>&lt;span&gt;
&lt;p&gt;Hi all,&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;My company Policies say that I have to at all times see who use&amp;#39;s the administrator accounts. I’ve been using Logparser to import Securitylog and Applicationslog (for the SQL server) into a SQL server. I’m using MS Access to extract reports. This is ok. &lt;/p&gt;
&lt;p&gt;The problem is to know at all times who is in the group Local Administrators. Normally this is known users, but in this hacker world you never no. So I wish to, someway, to import into an SQL table of all the users of Local Administrators, either they are Domain users or local users. Hope someone has any ideas by using Logparser combined with WMI.&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;Gsiqadm&lt;/p&gt;&lt;/span&gt;</description></item><item><title>Just Bought Book (new) Log Parser Toolkit by Giuseppini - Looking for new script download site</title><link>http://forums.iis.net/p/1155658/1895252.aspx#1895252</link><pubDate>Fri, 27 Feb 2009 23:53:39 GMT</pubDate><guid isPermaLink="false">50bcf3b4-f6fe-4638-adff-0c150e922e99:1895252</guid><dc:creator>Ed Grossheim</dc:creator><cs:applicationKey>general_discussion-51</cs:applicationKey><description>&lt;p&gt;5-49 pm&amp;nbsp; 02-27-09&lt;/p&gt;
&lt;p&gt;&amp;nbsp; The book says&amp;nbsp;4 e-booklets are available, and the scripts for the book. You must register at &amp;quot;syngress.com&amp;quot; which does not exist anymore&lt;/p&gt;
&lt;p&gt;&amp;nbsp; You are redirected to &lt;a href="http://www.elsevierdirect.com/"&gt;http://www.elsevierdirect.com/&lt;/a&gt; which yields no leads upon entering one search phrase after another.&lt;/p&gt;
&lt;p&gt;&amp;nbsp; Google yields nothing.&lt;/p&gt;
&lt;p&gt;&amp;nbsp; Would anyone know or offer to send me them?&lt;/p&gt;
&lt;p&gt;&amp;nbsp; Thanks, Ed&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>logparser samples</title><link>http://forums.iis.net/p/1155655/1895117.aspx#1895117</link><pubDate>Fri, 27 Feb 2009 21:41:08 GMT</pubDate><guid isPermaLink="false">50bcf3b4-f6fe-4638-adff-0c150e922e99:1895117</guid><dc:creator>pharr</dc:creator><cs:applicationKey>general_discussion-51</cs:applicationKey><description>&lt;p&gt;The following information was submitted in the past by customers. I&amp;#39;m reposting it here as-is. It contains various samples for using logparser.&lt;/p&gt;
&lt;h3&gt;Time-Constrained Queries&lt;/h3&gt;
&lt;p&gt;Here&amp;#39;s a way to slice queries by time:&lt;/p&gt;
&lt;div&gt;&lt;pre&gt;	LogParser &amp;quot;SELECT 
	EventLog, RecordNumber, TimeGenerated, EventID, EventType, EventTypeName, 
	EventCategory, SourceName, ComputerName, Message FROM System, Application, 
	Security TO tblEvents WHERE TO_STRING(TimeGenerated, &amp;#39;yyyyMMdd&amp;#39;) = 
	TO_STRING(TO_LOCALTIME(SYSTEM_TIMESTAMP()), &amp;#39;yyyyMMdd&amp;#39;) AND 
	TO_INT(TO_STRING(TimeGenerated, &amp;#39;HH&amp;#39;)) = 
	SUB(TO_INT(TO_STRING(TO_LOCALTIME(SYSTEM_TIMESTAMP()), &amp;#39;HH&amp;#39;)),1)&amp;quot; -o:SQL -server:SQLSERVER 
	-driver:&amp;quot;SQL Server&amp;quot; -database:EventLogs -username:sa -password:XXXXX -createtable:ON&lt;/pre&gt;
&lt;p&gt;This way, for example, whether I run the command at 9:00:00 or 9:15 or 9:45 or 9:59:59, it will always get the events from 8:00:00 – 8:59:59.&lt;/p&gt;&lt;/div&gt;
&lt;h3&gt;Microsoft Print Server Reports&lt;/h3&gt;
&lt;p&gt;&lt;a href="http://www.iis.net/downloads/files/logparser/samples/LogParserPrintJobReports.zip"&gt;LogParserPrintJobReports.zip&lt;/a&gt; contains example reports for Microsoft Print Server print jobs.&lt;/p&gt;
&lt;p&gt;Example output:&lt;/p&gt;&lt;pre&gt;FileOwner       FileSizeTotal   PagesPrintedTotal
ACVP00QA        79546825        34632
btdfci          1161198955      32379
qtyan           1193090146      22827
dgyuard         692137473       19488
ABVP00QW 28372018        16378
maklare         694898256       14711
ASVP00EW        12829138        14048

DatePrinted     FileSizeTotal   PagesPrintedTotal
2005-07         1937151412      23786
2005-08         4813694697      71478
2005-09         4256144126      70289
2005-10         5434451891      69645
2005-11         5157293144      71456
2005-12         4436677005      53183
2006-01         5747978162      81802
2006-02         5403575457      74912
2006-03         6452139823      64490
&lt;/pre&gt;
&lt;h3&gt;ISA Logs&lt;/h3&gt;
&lt;p&gt;Here is how to get a summary of a single User&amp;#39;s web traffic from ISA 2000 with extended logs. This query is getting all of the transactions for mydomain\porncruzeruser during Jan and February 2006.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;logparser &amp;quot;SELECT c-ip,TO_LOWERCASE(cs-username) As User,date,time,r-host,r-ip into &amp;#39;%userprofile%\desktop\report.csv&amp;#39; FROM &amp;#39;c:\Program Files\Microsoft ISA Server\ISALogs\WEBEXTD200602*.log&amp;#39;,&amp;#39;c:\Program Files\Microsoft ISA Server\ISALogs\WEBEXTD200601*.log&amp;#39; where User=&amp;#39;mydomain\porncruzeruser&amp;#39;&amp;quot; -i:w3c -o:CSV&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;VB6/SQL Sample&lt;/h3&gt;
&lt;div&gt;&lt;font size="2" face="Arial"&gt;&lt;a href="http://www.iis.net/downloads/files/logparser/samples/vb6.zip"&gt;Sample&lt;/a&gt; how to use COM-Object in VB6 with ODBC- DSN-Entry as SQL-Server Input&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;&lt;pre&gt;LogParser &amp;quot;SELECT * Into in200511.Log FROM IISReportParser&amp;quot; -i:COM -iProgID:ComParserSql.Application 
	-iCOMParams:User=sa;Pwd=sa;Where=&amp;quot;ServiceInstance=&amp;#39;W3SVC116&amp;#39; AND 
	Report=&amp;#39;2005-11&amp;#39; &amp;quot; -o:IIS&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;LogParserRegexInputFormat&lt;/h3&gt;
&lt;p&gt;&lt;a href="http://www.iis.net/downloads/files/logparser/samples/LogParserRegexInputFormat.zip"&gt;LogParserRegexInputFormat&lt;/a&gt; is a C# COM Plugin I wrote in VS 2005 that parses log files using an arbitrary regex and field type definitions configured in an XML file.&lt;/p&gt;
&lt;h3&gt;Log Parser GUI&lt;/h3&gt;
&lt;div&gt;
&lt;p&gt;&lt;font size="2" face="Arial"&gt;&lt;span&gt;I am one of those who are astounded by the power of LogParser. &amp;nbsp;I think a lot of people have not discovered it because they are put off by the command-line interface.&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2" face="Arial"&gt;&lt;span&gt;I am attaching a &lt;a href="http://www.iis.net/downloads/files/logparser/samples/simpleLPview00.zip"&gt;gui&lt;/a&gt; I have created in C# along the principle of KISS. &amp;nbsp;I realize it is pretty basic but I see it as a starting point. &amp;nbsp;Based on whatever feedback/assistance/tips I receive, I will develop it further.&amp;nbsp; I am providing all the code in the hope that anyone who sees errors or ways of improving it will help improve it. &amp;nbsp;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;&lt;/div&gt;
&lt;h3&gt;Where Clauses at the Command Line&lt;/h3&gt;
&lt;p&gt;As I write .sql files, I find that using a parameter like %logfiles% makes them much more useful – I think this is fairly common. My trick is that if you use quotes appropriately, you can sneak your where clause on the end. Example:&lt;br /&gt;&lt;br /&gt;SelectAll.sql:&lt;br /&gt;&amp;nbsp;&amp;nbsp; Select * from %logfile%&lt;br /&gt;&lt;br /&gt;cmd-line statement:&lt;br /&gt;&amp;nbsp;&amp;nbsp; logparser file:SelectAll.sql?logfile=”ex*.log where cs-uri-stem like ‘%.aspx’&lt;/p&gt;
&lt;h3&gt;LogParser Editor&lt;/h3&gt;
&lt;p&gt;A while back I created a little &lt;a href="http://www.iis.net/downloads/files/logparser/samples/LPEdit.zip"&gt;front end to LogParser&lt;/a&gt; (in VB) and haven&amp;#39;t been able to get back to it. I thought I would send the application to you just in case somebody wanted to use it or rewrite it and make it useable.&lt;/p&gt;
&lt;h3&gt;EventArchiver&lt;/h3&gt;
&lt;p&gt;&lt;a href="http://www.iis.net/downloads/files/logparser/samples/eventarchiver%20v1.5.zip"&gt;EventArchiver&lt;/a&gt; is a C# app i&amp;#39;ve written, its still alpha (some little bad inputs can crash it, still need to track these down, as long as user doesn&amp;#39;t do anything silly it should work) but the major functionality is there. This program is much more in depth.&lt;br /&gt;It has 3 modes: Configuration, command line, batch.&lt;br /&gt;The configuration mode lets you configure it to operate with MS SQL (set database name, user name, password, server, the password is encrypted by Rijndael 256 bit encryption)&lt;br /&gt;Once the SQL configuration is complete you can then either run through command line or through batch mode.&lt;br /&gt;To configure batch mode, once again enter configuration mode and go to s) Configure SQL batch mode.&lt;br /&gt;Here you can add servers, add credentials and link servers to credentials.&lt;br /&gt;&lt;br /&gt;The two output methods configured are CSV &amp;amp; SQL.&lt;br /&gt;&lt;br /&gt;Accepts the following switches:&lt;br /&gt;Downloads event logs from local or remote host and outputs to either a csv file&lt;br /&gt;or an sql table.&lt;br /&gt;&lt;br /&gt;EventArchiver [/?] [/h:host] [/o:outputType] [/d:destination] [/i:path]&lt;br /&gt;[&amp;lt;/u:username&amp;gt; &amp;lt;/p:password&amp;gt;] [/b] [/c[:config]] [/f[:config]]&lt;br /&gt;&lt;br /&gt;/? Brings up this screen.&lt;br /&gt;/h Specify host to connect to, if omitted will assume local.&lt;br /&gt;/o Specifies whether to output to SQL or to CSV file,&lt;br /&gt;if omitted will assume CSV file.&lt;br /&gt;outputType SQL - sql output format (default &amp;quot;TestSystems&amp;quot;)&lt;br /&gt;&lt;br /&gt;CSV - csv output format (default &amp;quot;c:\&amp;quot;)&lt;br /&gt;/d Specifies destination table (SQL) or directory (CSV).&lt;br /&gt;destination &amp;lt;table name&amp;gt; used for SQL format specified with /o switch.&lt;br /&gt;&amp;lt;directory name&amp;gt; used for CSV format specified with /o switch.&lt;br /&gt;/i Specifies destination path for checkpoint files&lt;br /&gt;/u Specify username (for domain accounts specify as DOMAIN\user).&lt;br /&gt;/p Specify password.&lt;br /&gt;/b Batch mode - uses SQL database for servers &amp;amp; credentials.&lt;br /&gt;/c Config mode - to configure SQL settings.&lt;br /&gt;config &amp;lt;filename&amp;gt; - Configuration file name.&lt;br /&gt;/f Use configuration file. (required for /o:SQL)&lt;br /&gt;config &amp;lt;filename&amp;gt; - Configuration file name.&lt;br /&gt;&lt;br /&gt;[] represents optional parameters, &amp;lt;&amp;gt; represents required paramters&lt;br /&gt;switches can be specified using &amp;#39;-&amp;#39; or &amp;#39;/&amp;#39;&lt;br /&gt;&lt;br /&gt;Some limitations, currently you cannot delete servers, credentials or batched runs, i haven&amp;#39;t had time to add this yet. Currently the only way to do this is to go into SQL&lt;br /&gt;&lt;br /&gt;Both programs (EventArchiver and PullLogs) will come packaged with some SQL scripts required to setup associated databases, the c# app can also be used to configure the database that the script will run off.&lt;/p&gt;
&lt;h3&gt;Pulling Event Logs&lt;/h3&gt;
&lt;p&gt;&lt;a href="http://www.iis.net/downloads/files/logparser/samples/PullLogs.zip"&gt;this utility&lt;/a&gt; will pull all the event logs from a remote machine to the local computer.&lt;/p&gt;
&lt;h3&gt;Using Log Parser from C#&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;try &lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Type comLogQueryType = Type.GetTypeFromProgID(&amp;quot;MSUtil.LogQuery&amp;quot;, true);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; object comLogQueryObject = Activator.CreateInstance(comLogQueryType);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Get the IIS Input and XML output filters&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Type ws3LogType = Type.GetTypeFromProgID(&amp;quot;MSUtil.LogQuery.IISW3CInputFormat&amp;quot;, true);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; object ws3LogObject = Activator.CreateInstance(ws3LogType);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Type xmlLogType = Type.GetTypeFromProgID(&amp;quot;MSUtil.LogQuery.XMLOutputFormat&amp;quot;, true);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; object xmlLogObject = Activator.CreateInstance(xmlLogType);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Setup input and output files&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; string inPath = &amp;quot;someIISlog.log&amp;quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; string outpath = &amp;quot;temp.xml&amp;quot;;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Create a SQL query to get the referers, count and uri-to. Order by total hits&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; string query=&amp;quot;SELECT cs(Referer) as Referer,cs-uri-stem as To,COUNT(*) as Total from &amp;quot;+inPath+&amp;quot; TO &amp;quot;+outpath+&amp;quot; \ &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHERE (sc-status=200) AND (Referer LIKE &amp;#39;http:%&amp;#39;) GROUP BY Referer,To ORDER BY Total DESC&amp;quot;;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Invoke the ExcuteBatch method&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; object[] inputArgs = {query, ws3LogObject, xmlLogObject};&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; comLogQueryType.InvokeMember(&amp;quot;ExecuteBatch&amp;quot;, BindingFlags.InvokeMethod, null, comLogQueryObject, inputArgs);&lt;br /&gt;}&lt;br /&gt;catch(Exception e)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; string errorString = &amp;quot;An exception has occurred: &amp;quot; + e.Message;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine(errorString);&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;This will create an XML file that has your uri&amp;#39;s that are refered to, hit count, and the referer.&lt;/p&gt;
&lt;h3&gt;Total Traffic Over a Time Period For Multiple IIS Sites&lt;/h3&gt;
&lt;p&gt;Scenario: I needed to determine the total amount of traffic over a time period for multiple sites on a Windows 2003 server. This entailed looping over all the sites in IIS, summarizing the bytes served for each site between two dates, then storing the results in a table for display and subsequent onward processing. &lt;br /&gt;&lt;br /&gt;LogParser&amp;#39;s recordset object as output was the obvious way to go instead of storing the various results in a bunch of separate XML/CSV files for each site. However, examples of this approach - especially using date ranges - were pretty rare and somewhat unintuitive to get working, so here&amp;#39;s my take on it (tested on Server 2003 &amp;amp; XP only):&lt;br /&gt;&lt;br /&gt;First, add a COM reference to the project. Browse to the LogParser install location and select LogParser.dll (the default location is C:\Program Files\IIS Resources\Log Parser). This creates a COM wrapper namespace called MSUtil. You will also need:&lt;br /&gt;&lt;br /&gt;----------------------------------&lt;br /&gt;using System.Data;&lt;br /&gt;using System.DirectoryServices;&lt;br /&gt;using System.Globalization;&lt;br /&gt;----------------------------------&lt;br /&gt;&lt;br /&gt;Next, create a holding table somewhere for the data:&lt;br /&gt;----------------------------------&lt;br /&gt;private DataTable tblTraffic = new DataTable(); private DataColumn dcSite = new DataColumn(&amp;quot;Site&amp;quot;); private DataColumn dcBytes = new DataColumn(&amp;quot;Bytes&amp;quot;); tblTraffic.Columns.Add(dcSite);&lt;br /&gt;tblTraffic.Columns.Add(dcBytes); &lt;br /&gt;tblTraffic.DefaultView.Sort = &amp;quot;Site&amp;quot;;&lt;br /&gt;----------------------------------&lt;br /&gt;&lt;br /&gt;Then run the core action routine as follows (assumes two datepicker controls for the From &amp;amp; To dates, and a datagrid for display):&lt;br /&gt;&lt;br /&gt;----------------------------------&lt;br /&gt;&lt;br /&gt;// create the LogParser object and associated IISW3C input object MSUtil.LogQueryClassClass LogParser = new MSUtil.LogQueryClassClass(); MSUtil.COMIISW3CInputContextClassClass IISlog = new MSUtil.COMIISW3CInputContextClassClass();&lt;br /&gt;&lt;br /&gt;// get the user-chosen date ranges from datepicker controls DateTime dtFrom = dtPickerFrom.Value; DateTime dtTo = dtPickerTo.Value;&lt;br /&gt;&lt;br /&gt;// create date format to match LogParser Timestamp field string strFormat = &amp;quot;yyyy-MM-dd&amp;quot;;&lt;br /&gt;&lt;br /&gt;// create From &amp;amp; To date strings in Timestamp format string strDateFrom = dtFrom.ToString(strFormat,&lt;br /&gt;DateTimeFormatInfo.InvariantInfo) + &amp;quot; 00:00:00&amp;quot;; string strDateTo = dtTo.ToString(strFormat,&lt;br /&gt;DateTimeFormatInfo.InvariantInfo) + &amp;quot; 23:59:59&amp;quot;; &lt;br /&gt;&lt;br /&gt;// find IIS sites properties via ADSI&lt;br /&gt;DirectoryEntry root = new DirectoryEntry(&amp;quot;IIS://localhost/W3SVC&amp;quot;);&lt;br /&gt;foreach(DirectoryEntry de in root.Children) {&lt;br /&gt;if (de.SchemaClassName == &amp;quot;IIsWebServer&amp;quot;)&lt;br /&gt;{ &lt;br /&gt;string strSiteName = de.Properties[&amp;quot;ServerComment&amp;quot;][0].ToString();&lt;br /&gt;&lt;br /&gt;// get numeric site identifier for use in FROM clause&lt;br /&gt;string strSiteID = de.Name.ToString();&lt;br /&gt;&lt;br /&gt;string strSQL = &amp;quot;SELECT SUM(sc-bytes) AS total &amp;quot;&lt;br /&gt;+ &amp;quot;FROM &amp;lt;&amp;quot; + strSiteID + &amp;quot;&amp;gt; &amp;quot;&lt;br /&gt;+ &amp;quot;WHERE TO_TIMESTAMP(date, time) &amp;gt;= &amp;quot;&lt;br /&gt;+ &amp;quot;TO_TIMESTAMP(&amp;#39;&amp;quot; + strDateFrom + &amp;quot;&amp;#39;, &amp;#39;yyyy-MM-dd hh:mm:ss&amp;#39;) &amp;quot; &lt;br /&gt;+ &amp;quot;AND TO_TIMESTAMP(date, time) &amp;lt;= &amp;quot;&lt;br /&gt;+ &amp;quot;TO_TIMESTAMP(&amp;#39;&amp;quot; + strDateTo + &amp;quot;&amp;#39;, &amp;#39;yyyy-MM-dd hh:mm:ss&amp;#39;) &amp;quot;;&lt;br /&gt;&lt;br /&gt;// prepare LogParser Recordset &amp;amp; Record objects&lt;br /&gt;MSUtil.ILogRecordset rsLP = null; &lt;br /&gt;MSUtil.ILogRecord rowLP = null; &lt;br /&gt;&lt;br /&gt;// run the query against the IIS log for this site&lt;br /&gt;rsLP = LogParser.Execute(strSQL,IISlog); &lt;br /&gt;rowLP = rsLP.getRecord();&lt;br /&gt;&lt;br /&gt;// populate holding table with site name &amp;amp; summary bytes for the period&lt;br /&gt;DataRow dr = tblTraffic.NewRow();&lt;br /&gt;dr[0] = strSiteName;&lt;br /&gt;dr[1] = rowLP.getValue(0);&lt;br /&gt;tblTraffic.Rows.Add(dr);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// show results in grid&lt;br /&gt;dgDisplay.DataSource = tblTraffic.DefaultView;&lt;br /&gt;&lt;br /&gt;----------------------------------&lt;br /&gt;&lt;br /&gt;This produces something like:&lt;br /&gt;&lt;br /&gt;Site Bytes&lt;br /&gt;------- -------&lt;br /&gt;Administration 304566&lt;br /&gt;BasicHackers 56438387&lt;br /&gt;CSharpCoders 46567439&lt;/p&gt;
&lt;h3&gt;Searches on a SharePoint Site&lt;/h3&gt;
&lt;p&gt;Here is a little LogParser SQL that I found useful in determining what users were searching for on our Intranet use SPS 2003 Search.&lt;/p&gt;
&lt;p&gt;I call it via &amp;quot;C:\Program Files\IIS Resources\Log Parser\LogParser&amp;quot; -o:csv file:search.sql&lt;/p&gt;
&lt;p&gt;search.sql:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;SELECT DISTINCT 
TO_UPPERCASE(EXTRACT_VALUE(cs-uri-query, &amp;#39;k&amp;#39;)) AS SearchString, 
EXTRACT_VALUE(cs-uri-query, &amp;#39;s&amp;#39;) AS Scope, COUNT(*) AS HowMany
FROM *.log
TO search.csv
WHERE cs-uri-stem = &amp;#39;/search.aspx&amp;#39;AND cs-uri-query NOT LIKE 
&amp;#39;%[Microsoft+Office+SharePoint+Portal+Server+2003+LOG]%&amp;#39; AND SearchString IS 
NOT NULL
GROUP BY SearchString, Scope
ORDER BY HowMany DESC
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Restarting a malfunctioning application&lt;/h3&gt;
&lt;p&gt;Here is a script in VB Script to address a problem that we had with a malfunctioning IIS application.&lt;br /&gt;&lt;br /&gt;I execute the script every 10 minutes to check the status of the IIS server.&lt;br /&gt;&lt;br /&gt;The script exams the IIS log to find rows with sc-status 200 and 500 written in the last 5 minutes.&lt;br /&gt;If the percentage of requests with sc-status 500 reaches a critical level the script then restarts the W3SVC service.&lt;br /&gt;&amp;nbsp;&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
&amp;#39; Restarts IIS when errors start appearing
Option Explicit
Dim oShell, oWMIService, oLogQuery, oIISW3CInputFormat
Dim oRecordSet, oRecord, oService
Dim strComputer, strQuery, perCentErrors, totalCorrect, flagStarted
Dim colServiceList, errReturn

Const perCentErrorThreshold = 10.0
Set oShell = WScript.CreateObject(&amp;quot;WScript.Shell&amp;quot;)
strComputer = &amp;quot;.&amp;quot;
Set oWMIService = GetObject(&amp;quot;winmgmts:&amp;quot; _
	&amp;amp; &amp;quot;{impersonationLevel=impersonate, (Security)}!\\&amp;quot; &amp;amp; _
	 strComputer &amp;amp; &amp;quot;\root\cimv2&amp;quot;)
Set oLogQuery = CreateObject(&amp;quot;MSUtil.LogQuery&amp;quot;)
Set oIISW3CInputFormat = CreateObject(&amp;quot;MSUtil.LogQuery.IISW3CInputFormat&amp;quot;)
&amp;#39;Create CheckPoint file 
oIISW3CInputFormat.iCheckPoint = &amp;quot;RecupWebApp.lpc&amp;quot;
&amp;#39;Create Query. Exams log in last 5 minutes for sc-status 200 and 500
&amp;#39;Returns 2 or less rows
strQuery = &amp;quot;SELECT sc-status, MUL(PROPCOUNT(*), 100.0), COUNT(*) FROM
&amp;lt;1&amp;gt; WHERE &amp;quot;
strQuery = strQuery &amp;amp; &amp;quot;SUB(TO_INT(TO_LOCALTIME(SYSTEM_TIMESTAMP())),&amp;quot;
strQuery = strQuery &amp;amp; &amp;quot;TO_INT(TO_LOCALTIME(TO_TIMESTAMP(date,time)))) &amp;lt; 300&amp;quot;
strQuery = strQuery &amp;amp; &amp;quot; AND (sc-status = 200 OR sc-status = 500) GROUP
BY sc-status&amp;quot;
&amp;#39;Execute query
Set oRecordSet = oLogQuery.Execute(strQuery,oIISW3CInputFormat)
Do While Not oRecordSet.atEnd
	Set oRecord = oRecordSet.getRecord
	If oRecord.getValue(0) = 500 Then
		perCentErrors = oRecord.getValue(1)
		totalErrors = oRecord.getValue(2)
	Else
		&amp;#39;cs-status = 200
		totalCorrect = oRecord.getValue(2)
	End If
	oRecordSet.MoveNext
Loop
&amp;#39;Write information to application event log
If perCentErrors &amp;gt; 0 Then
	oShell.LogEvent 0, &amp;quot;WebApp: Errors &amp;quot; &amp;amp; totalErrors &amp;amp; _
		&amp;quot; of a total of &amp;quot; &amp;amp; (100 * totalErrors)/perCentErrors
Else
	oShell.LogEvent 0, &amp;quot;WebApp: Errors 0 of a total of &amp;quot; &amp;amp; totalCorrect
End If
&amp;#39;Restart W3SVC if there are too many errors.
If perCentErrors &amp;gt; perCentErrorThreshold Then
	ReStartIIS
End If
oRecordSet.close

Sub ReStartIIS
	flagStarted = &amp;quot;n&amp;quot;
	Set colServiceList = oWMIService.ExecQuery(&amp;quot;SELECT * FROM
Win32_Service WHERE Name=&amp;#39;W3SVC&amp;#39;&amp;quot;)
	&amp;#39;Stop IIS
	For Each oService In colServiceList
		errReturn = oService.StopService()
		&amp;#39;Write information to application event Log
		oShell.LogEvent 2, &amp;quot;IIS stopped due to error in WebApp with code &amp;quot; &amp;amp; errReturn
		&amp;#39;Wait a while
		WScript.Sleep 55000
		Do While flagStarted = &amp;quot;n&amp;quot;
			&amp;#39;Wait a bit more
			WScript.Sleep 5000
			errReturn = oService.StartService()
			&amp;#39;Test to see if w3svc starts OK, if not try again 5 sec late
			If errReturn = 0 Then
				flagStarted = &amp;quot;y&amp;quot;
			End If
		Loop
	&amp;#39;Write information to application event Log
	oShell.LogEvent 0, &amp;quot;IIS Restarted&amp;quot;
	Next
End Sub

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;EventLogs.Zip&lt;/h3&gt;
&lt;p&gt;This &lt;a href="http://www.iis.net/downloads/files/logparser/samples/EventLogs.zip"&gt;zip file&lt;/a&gt;, contains a Log Parser script and supporting files. He says &amp;quot;I&amp;#39;d like to have a scheduled event executed every morning at 6:00AM. This event will backup all the event logs for the previous day and then convert the information to something that is easily readable. When I get into work, I can quickly look through a list of events and focus on those that need my attention. I&amp;#39;m still working on this, but here&amp;#39;s what I&amp;#39;ve got so far.&amp;quot;&lt;/p&gt;
&lt;h3&gt;HomeFolderReport.Zip&lt;/h3&gt;
&lt;p&gt;In this &lt;a href="http://www.iis.net/downloads/files/logparser/samples/HomeFolderReport.zip"&gt;zip file&lt;/a&gt;: &lt;/p&gt;
&lt;p&gt;A batch file that returns a report on a folder of these three values. &lt;br /&gt;&lt;br /&gt;1.) The top 10 largest files&lt;br /&gt;2.) The top 20 largest files that have not been written to in a year&lt;br /&gt;3.) The top 10 largest duplicate files.&lt;br /&gt;&lt;br /&gt;We have many users with LARGE home folders and I hope to use this to give them a tool to clean house. The way it works is put the batch file anywhere. The tpl files need to go in the Log Parser folder and a c:\log files folder needs to exist. The batch file works off 2 parameters; The location of the folder and a name for report. The syntax would;&lt;br /&gt;&lt;br /&gt;HFR FolderName-(usually the name of the users home folder) UserName&lt;br /&gt;&lt;br /&gt;Ex. HFR M:\ksowers ksowers&lt;br /&gt;&lt;br /&gt;This will return a report of the m:\ksowers folder called ksowers_HFR.html in the c:\log files folder&lt;/p&gt;
&lt;h3&gt;LogParser COM input plugin sample&lt;/h3&gt;
&lt;p&gt;&lt;a href="http://www.iis.net/downloads/files/logparser/samples/CCLogReader.zip"&gt;this sample&lt;/a&gt; contains a &amp;nbsp;COM input plugin to read some proprietary binary logs. The plugin itself won&amp;#39;t be useful to anyone but it&amp;#39;s a good sample for those who want to write one of their own.&lt;br /&gt;&lt;/p&gt;
&lt;h3&gt;Split IIS Logs&lt;/h3&gt;
&lt;p&gt;I use this console app to split the IIS logs using Host Headers into individual log files with directory name the domain name. This was a requirement for using LiveStats.&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
using System;
using MSUtil;
using System.Collections;
using System.IO;

namespace LogSplitter
{
      /// &amp;lt;summary&amp;gt;
      /// Summary description for Class1.
      /// &amp;lt;/summary&amp;gt;
      class Class1
      {
            /// &amp;lt;summary&amp;gt;
            /// The main entry point for the application.
            /// &amp;lt;/summary&amp;gt;
            [STAThread]
            static void Main(string[] args)
            {
                  MSUtil.LogQueryClassClass Log = new MSUtil.LogQueryClassClass(); 
                  MSUtil.COMIISW3CInputContextClass InputW3C = new MSUtil.COMIISW3CInputContextClass(); 
                  MSUtil.COMW3COutputContextClass OutputW3C = new MSUtil.COMW3COutputContextClass();
 
                  //record Set 
                  MSUtil.ILogRecordset Record = null; 
                  MSUtil.ILogRecord row = null; 
 
                  string strSourceFile = &amp;quot;&amp;quot;;
 
                  if (args.Length == 0)
                  {
                        strSourceFile = &amp;quot;ex&amp;quot;;
                        System.DateTime dtNow = System.DateTime.Now;
                        strSourceFile += dtNow.Year.ToString().Substring(2,2);
                        string strMonth = dtNow.Month.ToString();
                        if (dtNow.Month &amp;lt; 10) strMonth = &amp;quot;0&amp;quot; + strMonth;
 
                        strSourceFile += strMonth;
                        strSourceFile += (dtNow.Day-1).ToString();
                        strSourceFile += &amp;quot;.log&amp;quot;;
                  }
                  else
                        strSourceFile = args[0];
 
                  string QUERY1 = &amp;quot;Select distinct cs-host from &amp;quot; + strSourceFile + &amp;quot; order by cs-host&amp;quot;; 
                  Record = Log.Execute(QUERY1,InputW3C); 
 
                  ArrayList arDomains = new ArrayList(500);
                  ArrayList arLogs = new ArrayList(500);
 
                  while (!Record.atEnd() ) 
                  { 
                        //print 
                        row = Record.getRecord();
                        string RowColumns = row.getValue(0).ToString().ToLower();
                        arDomains.Add(RowColumns);
 
                        Record.moveNext();
                  } 
 
                  foreach(string strItem in arDomains)
                  {
                        //remove www.
                        string strDomain = strItem.Replace(&amp;quot;www.&amp;quot;,&amp;quot;&amp;quot;);
                        //do each one once for all combinations of domain
                        if (arLogs.Contains(strDomain) == false)
                        {
                              //create subdir
                              DirectoryInfo di = new DirectoryInfo(strDomain);
                              if (di.Exists == false)
                                    di.Create();
 
                              QUERY1 = &amp;quot;select * into &amp;quot; + strDomain + &amp;quot;\\&amp;quot; + strSourceFile + &amp;quot; from &amp;quot; + strSourceFile + &amp;quot; where cs-host = &amp;#39;&amp;quot;+ strDomain + &amp;quot;&amp;#39; OR cs-host = &amp;#39;www.&amp;quot; + strDomain + &amp;quot;&amp;#39;&amp;quot;;
            
                              Log.ExecuteBatch(QUERY1,InputW3C, OutputW3C);
                              arLogs.Add(strDomain);
                        }
                  }
 
            }
      }
}


&lt;/code&gt;&lt;/pre&gt;</description></item><item><title>General logparser information</title><link>http://forums.iis.net/p/1155654/1895114.aspx#1895114</link><pubDate>Fri, 27 Feb 2009 21:39:02 GMT</pubDate><guid isPermaLink="false">50bcf3b4-f6fe-4638-adff-0c150e922e99:1895114</guid><dc:creator>pharr</dc:creator><cs:applicationKey>general_discussion-51</cs:applicationKey><description>&lt;p&gt;The following information was submitted in the past by customers. I&amp;#39;m reposting it here as-is.&amp;nbsp; It contains some general informaiton and some troubleshooting information.&lt;/p&gt;
&lt;h3&gt;Can&amp;#39;t install Log Parser 2.1 on Windows 2000&lt;br /&gt;&lt;/h3&gt;
&lt;p&gt;Version: 2.1&lt;/p&gt;
&lt;p&gt;The procedure for getting Log Parser 2.1 on to a Windows 2000 box is non-obvious. You can&amp;#39;t just run the setup, because it will fail on any operating system other than Windows XP and Windows 2003.&lt;/p&gt;
&lt;p&gt;Though the IIS 6.0 Resource Kit itself is limited to Windows 2003 and Windows XP, Log Parser 2.1 runs fine on Windows 2000. The trick is getting it there. You have two options to do this. The first is to install to a Windows 2003 or Windows XP box, and then copy the Program Files\IIS Resources\Log Parser folder to your Windows 2000 box. If that&amp;#39;s not an option, you can still get the files by performing an administrative installation directly to your Windows 2000 computer. Download the iis60rkt.exe file to your computer and open a command prompt window to the directory where you saved the file. Then execute this command line:&lt;/p&gt;&lt;pre&gt;iis60rkt.exe /V/a&lt;/pre&gt;
&lt;p&gt;The InstallShield Wizard will appear and ask you where to place the files for the administrative install. Specify a directory such as c:\Temp, and then you&amp;#39;ll find the Log Parser 2.1 files in c:\Temp\program files\IIS Resources\Log Parser.&lt;/p&gt;
&lt;h3&gt;What is the current version of Log Parser?&lt;/h3&gt;
&lt;p&gt;The current version of Log Parser is Log Parser 2.2, which is available directly from the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=890cd06b-abf8-4c25-91b2-f8d975cf8c07&amp;amp;displaylang=en"&gt;Microsoft Download site&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;What operating systems will Log Parser run on?&lt;br /&gt;&lt;/h3&gt;
&lt;p&gt;Log Parser runs on Windows 2000, Windows XP, Windows Server 2003, or Windows Server 2008.&lt;/p&gt;
&lt;h3&gt;Date Arithmetic (2.1)&lt;br /&gt;&lt;/h3&gt;Starting in version 2.1, you can perform date arithmetic in the WHERE clause. Here&amp;#39;s an example:&lt;pre&gt;LogParser &amp;quot;SELECT EventLog, RecordNumber, TimeGenerated, EventID, EventType, EventTypeName, EventCategory, SourceName, ComputerName, Message FROM System, Application, Security WHERE TO_DATE(TimeGenerated) = TO_DATE(SUB(SYSTEM_TIMESTAMP(), TO_TIMESTAMP(&amp;#39;01-02&amp;#39;, &amp;#39;MM-dd&amp;#39;)))&amp;quot; -o:DATAGRID&lt;/pre&gt;
&lt;p&gt;The origin date for timestamp values is 0000-01-01 00:00:00, so 0000-01-02 00:00:00 represents a span of exactly one day.&lt;/p&gt;
&lt;h3&gt;Write a query that returns records that are not already in the output file&lt;br /&gt;&lt;/h3&gt;
&lt;p&gt;Note: In version 2.2, you can use the new Checkpoint feature to solve this problem in many cases. See the help topic &amp;quot;Parsing Input Incrementally&amp;quot;.&lt;/p&gt;
&lt;p&gt;Versions: 2.0, 2.1&lt;/p&gt;
&lt;p&gt;You can&amp;#39;t directly write a query that returns only records that are not already in the output file; that would require joining data from two different sources (the input file and the output file). Log Parser is planned to support multiple inputs in the same query in version 3.0, which will ship at some unknown point in the future. However, you may be able to get the required results with one of two different hacks. First, if the output is a SQL table, you can set a unique index on the table and just let inserts that violate the uniqueness constraint fail. Second, you may be able to use a sub-select if you have a different file that already contains the records that were previously inserted:&lt;/p&gt;&lt;pre&gt;SELECT * FROM NewLog.LOG &lt;br /&gt;TO Dest &lt;br /&gt;WHERE (datetime field) &amp;gt; (SELECT Max(datetime field) FROM OldLog.log)&lt;/pre&gt;
&lt;h3&gt;Use Windows authentication with SQL Server ouput&lt;br /&gt;&lt;/h3&gt;To use Windows authentication when using SQL Server as the output target for Log Parser, just leave out the username and password parameters in the Log Parser command line. Log Parser will default to integrated authentication. 
&lt;h3&gt;Source of Query and Template Samples&lt;br /&gt;&lt;/h3&gt;
&lt;p&gt;Worth reading is Mark Burnett&amp;#39;s article for SecurityFocus, &lt;a href="http://securityfocus.com/infocus/1712"&gt;Forensic Log Parsing with Microsoft&amp;#39;s Log Parser&lt;/a&gt;, showing how to use Log Parser to hunt through IIS logs looking for suspicious patterns.&lt;/p&gt;
&lt;h3&gt;Use an Access Database for Log Parser output&lt;br /&gt;&lt;/h3&gt;
&lt;p&gt;Here&amp;#39;s a full example of how to use a Microsoft Access database as the target for Log Parser output:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;div&gt;Create your Access database. &lt;/div&gt;
&lt;li&gt;
&lt;div&gt;Create the target table in your Access database. In Log Parser 2.0, the -createtable switch has a problem with Access databases (see the related article)You may need to play around some to get the data types right, but fortunately the error messages if you get it wrong are pretty clear. For this example, I created a table named Files with three fields: FName (Text, 255), Size (Number, Long Integer), and Attributes (Text, 255).&lt;/div&gt;
&lt;li&gt;
&lt;div&gt;Create an ODBC DSN to point to the database. On Windows 2000, you do this from Programs, Administrative Tools, Data Sources (ODBC). I created a System DSN named LPtest that refers to my Access database. You&amp;#39;ll find when you create the DSN that you get to select a driver (Microsoft Access, of course) and then browse to the database (the &amp;quot;Select&amp;quot; button on the setup dialog box will do this).&lt;/div&gt;
&lt;li&gt;
&lt;div&gt;Now you can run a Log Parser query that uses the DSN to get to the database. For this example, I used: &lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;pre&gt;logparser &amp;quot;SELECT Name AS FName, Size, Attributes &lt;br /&gt;FROM c:\winnt\system32\*.* TO Files&amp;quot; -i:FS -o:SQL -dsn:LPtest&lt;/pre&gt;
&lt;h3&gt;Escape commas in CSV output&lt;br /&gt;&lt;/h3&gt;
&lt;p&gt;When outputting query results to -o:CSV format, any commas that are embedded in the data are not escaped. Consequently, reading the results into Excel will be done improperly.&lt;/p&gt;
&lt;p&gt;&lt;u&gt;Workaround for 2.0:&lt;/u&gt;&lt;/p&gt;
&lt;p&gt;You can use the &lt;code&gt;REPLACE_CHR&lt;/code&gt; function, as in:&lt;/p&gt;&lt;pre&gt;&amp;quot;SELECT ...., REPLACE_CHR(cs-uri-query, &amp;#39;,&amp;#39;, &amp;#39;+&amp;#39;), ...&amp;quot; &lt;/pre&gt;
&lt;p&gt;which will automatically replace any occurrence of &amp;#39;,&amp;#39; with &amp;#39;+&amp;#39;.&lt;/p&gt;
&lt;p&gt;If double quotes are preferred, you can use the &lt;code&gt;STRCAT&lt;/code&gt; function:&lt;/p&gt;&lt;pre&gt;&amp;quot;SELECT ...., STRCAT(&amp;#39;&amp;quot;&amp;#39;, STRCAT(cs-uri-query, &amp;#39;&amp;quot;&amp;#39;)), ...&amp;quot;&lt;/pre&gt;
&lt;p&gt;&lt;u&gt;New switch in 2.1:&lt;/u&gt;&lt;/p&gt;
&lt;p&gt;In version 2.1, the CSV and W3C output formats have a new &amp;quot;encodeDelim&amp;quot; option (default=false), which will automatically encode &amp;#39;,&amp;#39; (for CSV) and space (for W3C) as &amp;#39;+&amp;#39;.&lt;/p&gt;
&lt;h3&gt;Include a column name that contains a space in the SELECT statement&lt;/h3&gt;
&lt;p&gt;Versions: 2.0, 2.1&lt;/p&gt;
&lt;p&gt;Including column names containing spaces in your SQL statements requires special syntax. In Log Parser 2.0, you can use \u0020 to represent a space in Unicode:&lt;/p&gt;&lt;pre&gt;logparser &amp;quot;SELECT Virus\u0020Type, Virus\u0020Name &lt;br /&gt;FROM log.csv&amp;quot; -i:CSV -headerRow:ON&lt;/pre&gt;
&lt;p&gt;In Log Parser 2.1, you can surround field names with the SQL quoting square brackets instead:&lt;/p&gt;&lt;pre&gt;logparser &amp;quot;SELECT [Virus Type], [Virus Name] &lt;br /&gt;FROM log.csv&amp;quot; -i:CSV -headerRow:ON&lt;/pre&gt;
&lt;h3&gt;Use event logs with spaces in their names&lt;/h3&gt;
&lt;p&gt;Some event logs (such as Directory Service, DNS Server, and File Replication Service) have spaces in their names. To get Log Parser to recognize these files, you need to do two things:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Specify the -i EVT switch to tell LogParser specifically that this is an Event Log&lt;/li&gt;
&lt;li&gt;Replace spaces in the log name with the Unicode-escaped space \u0020&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;So, for example, this query will give you the EventIDs for ten FRS events:&lt;/p&gt;&lt;pre&gt;logparser -i EVT &amp;quot;SELECT TOP 10 EventID &lt;br /&gt;FROM File\u0020Replication\u0020Service&amp;quot;&lt;/pre&gt;
&lt;h3&gt;Use remote event logs with spaces in their names&lt;/h3&gt;
&lt;p&gt;Version: 2.1&lt;br /&gt;Fixed in: 2.2&lt;/p&gt;
&lt;p&gt;Attempting to retrieve information from an event log such as File Replication Services on a remote server may fail. For instance, this command line:&lt;/p&gt;&lt;pre&gt;LogParser -i:EVT -o:CSV &lt;br /&gt;&amp;quot;SELECT * FROM \\myNetworkServer\File\u0020Replication\u0020Service &lt;br /&gt;TO test.csv&amp;quot;&lt;/pre&gt;
&lt;p&gt;may return the following error:&lt;/p&gt;&lt;pre&gt;ERROR: Error while looking for files: Error searching for files in folder \\myNetworkServer\File Replication Service: The network path was not found.&lt;/pre&gt;
&lt;p&gt;The problem isn&amp;#39;t actually the spaces in the name. Log Parser checks the registry to verify event log names before issuing the query. There&amp;#39;s a bug in all versions of Log Parser through 2.1 that causes it to incorrectly check the local registry rather than the remote registry, so if the event log you&amp;#39;re trying to retrieve doesn&amp;#39;t exist on the local computer, the query will fail. The workaround is to create a registry key for the desired event log in HKLM\System\CurrentControlSet\Services\EventLog. To make the example work, just add a File Replication Services subkey on your local machine.&lt;/p&gt;
&lt;p&gt;There&amp;#39;s an additional problem if your local computer has a different %systemroot% than the remote computer; in this case, it may not be able to retrieve message descriptions for remote event log entries. The only workaround for this is to copy the EventMessageFile registry keys, and the files they point to, from the remote computer to your own computer, placing the files in a known location. &lt;/p&gt;
&lt;h3&gt;Read Windows 2000 Event logs saved as CSV&lt;br /&gt;&lt;/h3&gt;
&lt;p&gt;You may encounter difficulties when trying to retrieve information from Windows 2000 event logs saved as CSV files. Here&amp;#39;s an example to show how to pull out events by ID number from such files.&lt;/p&gt;
&lt;p&gt;The first hurdle when using a CSV generated from an event log is that it doesn&amp;#39;t include field names -- LogParser will simply call them Field1, Field2, and so on. I took a look at the standard format for an exported event log and it looks like this to me:&lt;/p&gt;
&lt;p&gt;Field1 - Date&lt;br /&gt;Field2 - Time&lt;br /&gt;Field3 - Source&lt;br /&gt;Field4 - Type&lt;br /&gt;Field5 - Category&lt;br /&gt;Field6 - Event&lt;br /&gt;Field7 - User&lt;br /&gt;Field8 - Computer&lt;br /&gt;Field9 - Description&lt;/p&gt;
&lt;p&gt;So, given a file named security.csv, you could extract all of the 560 Events with this line:&lt;/p&gt;&lt;pre&gt;logparser &amp;quot;SELECT Field1 AS Date, Field2 AS Time, Field7 AS User, Field9 AS Description &lt;br /&gt;FROM c:\Temp\Securiy.csv WHERE Field6=560&amp;quot; -i:csv -headerRow:Off&lt;/pre&gt;
&lt;h3&gt;Cannot Find &amp;#39;Fields&amp;#39; Directive when parsing IIS log file&lt;/h3&gt;
&lt;p&gt;Attempting to run a query against an IIS log file may return an unexpected error. For example, you attempt to run this query:&lt;/p&gt;
&lt;p&gt;logparser -i:IISW3C -o:CSV &amp;quot;SELECT cs-uri-stem FROM iislog.log&amp;quot;&lt;/p&gt;
&lt;p&gt;You receive this error:&lt;/p&gt;
&lt;p&gt;Cannot Find &amp;#39;Fields&amp;#39; directive&lt;/p&gt;
&lt;p&gt;This indicates that the files you are trying to parse are in NCSA format, rather than native IIS format. Use the -i:NCSA switch with the query. Change the field names into those displayed by running&lt;/p&gt;
&lt;p&gt;logparser -h -i:NCSA&lt;/p&gt;
&lt;h3&gt;Timestamp basics&lt;/h3&gt;
&lt;p&gt;Timestamp is a Log Parser data type that can contain a date, a time, or both. Timestamps have two basic functions. Firtst, they can hold an entire date and time. For example, returning the current system time as a timestamp:&lt;/p&gt;
&lt;p&gt;SYSTEM_TIMESTAMP()&lt;/p&gt;
&lt;p&gt;Note that SYSTEM_TIMESTAMP() returns UTC time.&lt;/p&gt;
&lt;p&gt;You can create such a timestamp by combining two timestamps, one of which contains a date and one of which contains a time. For example, you can get the current system date as a timestamp with SYSTEM_DATE() and the current system time as a timestamp with SYSTEM_TIME(), so a longwinded replacement for SYSTEM_TIMESTAMP() is&lt;/p&gt;
&lt;p&gt;TO_TIMESTAMP(SYSTEM_DATE(), SYSTEM_TIME())&lt;/p&gt;
&lt;p&gt;Timestamps can also be used to hold a span of time. For this, you can use the second form of TO_TIMESTAMP(), which takes a string value indicating a date or time (or both), and a formatting string. You can also use the equivalent TIMESTAMP() data type, which is constructed the same way. For example, returning a 12-hour timestamp (holds twelve hours in the first day of the year zero):&lt;/p&gt;
&lt;p&gt;TIMESTAMP(&amp;#39;12:00:00&amp;#39;, &amp;#39;hh:mm:ss&amp;#39;)&lt;/p&gt;
&lt;p&gt;Returning a 24-hour timestamp:&lt;/p&gt;
&lt;p&gt;TIMESTAMP(&amp;#39;2&amp;#39;, &amp;#39;d&amp;#39;)&lt;/p&gt;
&lt;p&gt;(Why not TIMESTAMP(&amp;#39;1&amp;#39;, &amp;#39;d&amp;#39;)? Because the origin of the date values is day 1 of year zero. So you need to ask for the start of the &lt;em&gt;second&lt;/em&gt; day to get 24 hours of time.)&lt;/p&gt;
&lt;p&gt;Returning a 48-hour timestamp (2 days in year zero):&lt;/p&gt;
&lt;p&gt;TIMESTAMP(&amp;#39;3&amp;#39;, &amp;#39;d&amp;#39;)&lt;/p&gt;
&lt;p&gt;You can use timestamp math to move around timezones. For example, to move a time from GMT to GMT-6, you&amp;#39;d subtract a six-hour timestamp:&lt;/p&gt;
&lt;p&gt;SUB( FieldWithGMTTimestamp, TIMESTAMP(&amp;#39;06:00:00&amp;#39;, &amp;#39;hh:mm:ss&amp;#39;))&lt;/p&gt;
&lt;p&gt;If you&amp;#39;re trying to go from GMT to your computer&amp;#39;s local time, there&amp;#39;s a shortcut TO_LOCALTIME(). The reverse shortcut is TO_UTCTIME().&lt;/p&gt;
&lt;p&gt;You can also use timestamp math in WHERE clauses to get recent events. For example, to get events in the last two hours, you&amp;#39;d look to see whether a particular time was more recent than a time created by subtracting a two-hour timestamp fro the current time:&lt;/p&gt;
&lt;p&gt;[.....] WHERE&amp;nbsp;FieldWithGMTTimestamp &amp;gt;= SUB(SYSTEM_TIMESTAMP(), TIMESTAMP(&amp;#39;02:00:00&amp;#39;, &amp;#39;hh:mm:ss&amp;#39;))&lt;/p&gt;
&lt;p&gt;To extract just the date from a timestamp into another timestamp, use TO_DATE(). To extract just the time from a timestamp into another timestamp, use TO_TIME().&lt;/p&gt;
&lt;h3&gt;Retrieve data from file with a space in the filename&lt;/h3&gt;
&lt;p&gt;Version: 2.1&lt;/p&gt;
&lt;p&gt;If you have a filename such as &amp;quot;Copy of MyFile.csv&amp;quot;, you may have trouble retrieving data from the file. A simple query such as &amp;quot;SELECT * FROM Copy of MyFile.csv&amp;quot; will fail with a syntax error.&lt;/p&gt;
&lt;p&gt;The solution is to Unicode-encode the space characters: &amp;quot;SELECT * FROM Copy\u0020of\u0020MyFile.csv&amp;quot;.&lt;/p&gt;
&lt;p&gt;In general, you can use \u followed by hexadecimal numbering to represent any arbitrary characters in Log Parser queries.&lt;/p&gt;
&lt;p&gt;Note: In Log Parser 2.2, you can also use single quotes to delimit the FROM clause. So beginning in 2.2 you can say &amp;quot;SELECT * FROM &amp;#39;Copy of MyFile.csv&amp;#39;&amp;quot;&lt;/p&gt;
&lt;h3&gt;Failure to parse comma-separated FROM clause&lt;/h3&gt;
&lt;p&gt;Version: 2.2&lt;/p&gt;
&lt;p&gt;Log Parser 2.2 may fail to correctly parse a comma-separated list of elements in the FROM clause. If a comma character in the FROM clause is followed by whitespace (space/tab/carriage-return/line-feed), parsing will fail.&lt;/p&gt;
&lt;p&gt;Workaround: Remove all spaces after commas in the FROM clause.&lt;/p&gt;
&lt;h3&gt;Can&amp;#39;t direct output to database other than SQL Server&lt;/h3&gt;
&lt;p&gt;You may encounter difficulties exporting to an ODBC data source that doesn&amp;#39;t support the SQL datatypes that LogParser is using. One possible workaround (reported to be successful with Oracle) is to convert all columns to strings with the TO_STRING function, and to provide a table in your datasource whose columns are predefined as varchar2 columns.&lt;/p&gt;
&lt;p&gt;Another (and usually superior, if you have direct administrative access to the database) is to create the target table yourself before you perform the export. That way you can use any data type that LogParser itself can handle in updating an existing table, without being limited to string fields.&lt;/p&gt;
&lt;h4&gt;Retrieve events in the last calendar month&lt;/h4&gt;
&lt;p&gt;There&amp;#39;s no clean way to write SQL to retrieve only log entries for the last calendar month - that is, from today minus the number of day&amp;#39;s in today&amp;#39;s month, so if today is March 4 you want to see events from February 5 to March 4. Here&amp;#39;s a hack suggested by Gabriele Giuseppini:&lt;/p&gt;&lt;span id="_ctl2_ThreadRepeater__ctl4_lblFullMessage"&gt;SELECT ....&lt;/span&gt;&lt;span id="_ctl2_ThreadRepeater__ctl4_lblFullMessage"&gt; 
&lt;p&gt;USING TO_TIMESTAMP([your stuff]) AS Now,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TO_TIMESTAMP(&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CASE TO_STRING(Now, &amp;#39;M&amp;#39;)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHEN &amp;#39;1&amp;#39; THEN &amp;#39;02-01&amp;#39;&amp;nbsp;&amp;nbsp;// 31 days&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHEN &amp;#39;2&amp;#39; THEN &amp;#39;01-29&amp;#39;&amp;nbsp; // Broken on leap years&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHEN &amp;#39;3&amp;#39; THEN &amp;#39;02-01&amp;#39;&amp;nbsp; // 31 days&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHEN &amp;#39;4&amp;#39; THEN &amp;#39;01-31&amp;#39;&amp;nbsp; // 30 days&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ......&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; END, &amp;#39;MM-dd&amp;#39;) AS DaysInMonth&lt;/p&gt;
&lt;p&gt;... WHERE TimeGenerated &amp;gt;= SUB( Now, DaysInMonth) &lt;/p&gt;&lt;/span&gt;
&lt;h3&gt;What&amp;#39;s new in Log Parser 2.2&lt;/h3&gt;
&lt;p&gt;Changes to Log Parser 2.2 include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;New input formats (XML, TSV, ADS, COM, REG, NETMON, and ETW)&lt;/li&gt;
&lt;li&gt;New output formats (CHART, TSV, SYSLOG)&lt;/li&gt;
&lt;li&gt;GROUP BY WITH ROLLUP&lt;/li&gt;
&lt;li&gt;DISTINCT in aggregate functions&lt;/li&gt;
&lt;li&gt;PROPSUM and PROPCOUNT&lt;/li&gt;
&lt;li&gt;A whole bunch of new functions including MOD, ROUND, FLOOR, EXTRACT_FILENAME, HEX_TO_ASC, and more&lt;/li&gt;
&lt;li&gt;USING clause for temporary field expressions&lt;/li&gt;
&lt;li&gt;BETWEEN in WHERE or HAVING clauses&lt;/li&gt;
&lt;li&gt;SELECT CASE&lt;/li&gt;
&lt;li&gt;New date/time formats: milliseconds, nanoseconds, AM/PM&lt;/li&gt;
&lt;li&gt;Many new parameters for input and output formats&lt;/li&gt;
&lt;li&gt;Parameters in stored SQL files&lt;/li&gt;
&lt;li&gt;Permanent overrides to default global options&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;These are just the highlights. See the Log Parser 2.2 help file for full details.&lt;/p&gt;
&lt;h3&gt;Strange results when inserting data into MySQL database&lt;/h3&gt;
&lt;p&gt;When inserting data into a MySQL database, you may find strange or nonsensical data in the resulting table. It doesn&amp;#39;t matter whether you let Log Parser create the table, or whether you create it yourself. This is due to a bug in the MyODBC driver that occurs in (at least) versions 3.51.04 through 3.51.11.&lt;/p&gt;
&lt;p&gt;Currently there is no resolution or workaround.&lt;br /&gt;&lt;/p&gt;</description></item><item><title>pulling out a string with SUBSTR()</title><link>http://forums.iis.net/p/1153978/1888409.aspx#1888409</link><pubDate>Fri, 26 Dec 2008 18:48:19 GMT</pubDate><guid isPermaLink="false">50bcf3b4-f6fe-4638-adff-0c150e922e99:1888409</guid><dc:creator>daniel45</dc:creator><cs:applicationKey>general_discussion-51</cs:applicationKey><description>&lt;p&gt;Hi&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;I would like to pull a string out from a field of a variable length, where the length is defined by index_of(&amp;quot;string2&amp;quot;) - index_of(&amp;quot;string1&amp;quot;), that is the field looks like this &amp;quot;some stuff string1 string string2&amp;quot;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;I&amp;#39;ve tried doing it like this SUBSTR(field, INDEX_OF(&amp;#39;string1&amp;#39;), INDEX_OF(&amp;#39;string2&amp;#39;) - INDEX_OF(&amp;#39;string1&amp;#39;))&lt;/p&gt;&lt;p&gt;but logparser is refusing to accept this, and it is the &amp;quot;algebraic&amp;quot; part that is the problem.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Does anyone have any ideas to solve this.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Regards Daniel. &lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Log Parsing help for a beginer</title><link>http://forums.iis.net/p/1145815/1878751.aspx#1878751</link><pubDate>Mon, 08 Sep 2008 14:00:34 GMT</pubDate><guid isPermaLink="false">50bcf3b4-f6fe-4638-adff-0c150e922e99:1878751</guid><dc:creator>jellis_ms</dc:creator><cs:applicationKey>general_discussion-51</cs:applicationKey><description>&lt;p&gt;There is a book. Search Amazon.com for &amp;quot;LogParser&amp;quot;&lt;/p&gt;
&lt;p&gt;There is also a compiled list from this website on&amp;nbsp;&lt;a href="http://linuxlore.blogspot.com/"&gt;http://linuxlore.blogspot.com/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Search the page for &amp;quot;LogParser&amp;quot;&lt;/p&gt;</description></item><item><title>Link not working</title><link>http://forums.iis.net/p/1149569/1870400.aspx#1870400</link><pubDate>Wed, 28 May 2008 11:25:00 GMT</pubDate><guid isPermaLink="false">50bcf3b4-f6fe-4638-adff-0c150e922e99:1870400</guid><dc:creator>thompsonson</dc:creator><cs:applicationKey>feedback--1</cs:applicationKey><description>&lt;p&gt;Hi Chaps,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;the link to the LogParser Documentation is coming back with a 404...&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.iis.net/Downloads/files/LogParser/LogParser-ENU.chm"&gt;http://www.iis.net/Downloads/files/LogParser/LogParser-ENU.chm&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Anyone know where else this can be found?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Cheers,&lt;/p&gt;
&lt;p&gt;Matt&lt;/p&gt;</description></item></channel></rss>