Link to home
Start Free TrialLog in
Avatar of itsmevic
itsmevicFlag for United States of America

asked on

How to Pipe Logparser into VBScript - MUCHO POINTS!!!!

Hello,

    Does anyone know how I could pipe the Logparser application into a VBScript?  For example, if I used the below script.

    Basically, now I have to run the script seperately, it turns the log file into a readable .CSV file and from there I can parse through it separately using the MS LogParser application.  I'd like to however consolidate this process into ONE process just by executing the script alone.

    This is the pattern of events I'm hoping for:

1.)  Double-click on script to initiate.
2.)  Script opens dialog box, where I can choose a file that I want to Audit.
3.)  I click Open.
4.)  The script then copy's the file, moves it to Folder A where it's converted in the process to a .CSV file.
5.)  This is where I'd like to pipe the LogParser program into the script.
6.)  The script will then go out say somewhere on my C drive where I have a .TXT file that contains the LogParser SQL statement that I want it to perform, grabs that text file embeds it automatically in the Logparser program and then it performs the action i'm needing it to do based on the LogParser SQL statement that I've choosen.

     Is this possible?  I posted this question once before, but the technical scope of it may have been outside the reach of this site, wasn't sure because I never got a response back.


Set objDialog = CreateObject("UserAccounts.CommonDialog")
 
strHeader = "EVTTYPE,DATE,TIME,EVT,EVTID,STATUS,ACCOUNT,DOMAIN/USER,DC"
 
objDialog.Filter = "VBScript Scripts|*.vbs|All Files|*.*"
objDialog.FilterIndex = 1
objDialog.InitialDir = "\\my-server\logs\LogOns"
intResult = objDialog.ShowOpen
 
If intResult = 0 Then
    Wscript.Quit
End If
 
Dim fso, DestFilename
Dim SourceFileName, Source, TopDestPath, basename, dot, SendtoPath
 
TopDestPath = "\\my-server\logs\LogOns"
SendtoPath = "\\my-server\logs$\Folder A"
 
Set fso = CreateObject("Scripting.FileSystemObject")
Source = objDialog.FileName
SourceFileName = fso.GetFileName(Source)
Set DestFileName = fso.GetFile(Source)
 
dot = InStr(SourceFileName, ".")
basename = Left(SourceFileName, dot-1)
DestFileName.Copy SendToPath & "\" & basename & ".csv", True
wscript.echo SourceFileName & " copied to " & SendToPath & "\" & basename & ".csv"
Set objCSV = fso.OpenTextFile(SendtoPath & "\" & basename & ".csv", 1, False)
strNewContents = strHeader & VbCrLf & objCSV.ReadAll
objCSV.Close
Set objCSV = fso.CreateTextFile(SendtoPath & "\" & basename & ".csv", True)
objCSV.Write strNewContents
objCSV.Close
Set objCSV = Nothing
 
Set fso = nothing
Set DestFileName = nothing

Open in new window

Avatar of RobSampson
RobSampson
Flag of Australia image

Hi, I'm sure this can be done.....perhaps it might help us though, if you could post a sample log parser file, and the SQL statement, and the command that you run against the log to use that SQL statement. I can't remember exactly how the Log Parser works, so that would help....

Regards,

Rob.
Avatar of itsmevic

ASKER

Hi Rob,

    The Sample of the log file would be like this:

DATE            TIME           DOMAIN/USER       COMPUTERNAME             IP                           DC
03/17/2009   00:03:30    MYDOMAIN/USER       MYPC                 XXX.XXX.XX.XXX     TEST-DC
"                       "                     "                              "                               "                             "
"                       "                     "                              "                               "                             "
ECT...ECT...ECT....

I'd then run my VBScript file that copies and moves the file to another folder and renames to a .CSV file.

Then from there I will run Logparser....

My Logparser code would be as such:  (simplified but basically the same)

Logparser -i:CSV  -o:DATAGRID "SELECT * FROM \\my-server\logs\Folder A"

Hopefully this will help.  Thanks.
OK, so give this a shot.

What it does is copy the files as before, adding the header to the CSV files, then once it's done that, it reads the SQL command from the text file pointed to by
SQLCmdPath = "C:\Temp\SQLCommand.txt"

and runs the sample LogParser command you specified, using that statement.

P.S. You need to specify the path to LogParser.exe with this line
LogParserPath = "\\my-server\logs$\Logparser.exe"

Regards,

Rob.
Set objDialog = CreateObject("UserAccounts.CommonDialog")
 
strHeader = "EVTTYPE,DATE,TIME,EVT,EVTID,STATUS,ACCOUNT,DOMAIN/USER,DC"
 
objDialog.Filter = "VBScript Scripts|*.vbs|All Files|*.*"
objDialog.FilterIndex = 1
objDialog.InitialDir = "\\my-server\logs\LogOns"
intResult = objDialog.ShowOpen
 
If intResult = 0 Then
    Wscript.Quit
End If
 
Dim fso, DestFilename
Dim SourceFileName, Source, TopDestPath, basename, dot, SendtoPath
 
TopDestPath = "\\my-server\logs\LogOns"
SendtoPath = "\\my-server\logs$\Folder A"
LogParserPath = "\\my-server\logs$\Logparser.exe"
SQLCmdPath = "C:\Temp\SQLCommand.txt"
 
Set fso = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Scripting.FileSystemObject")
 
Source = objDialog.FileName
SourceFileName = fso.GetFileName(Source)
Set DestFileName = fso.GetFile(Source)
LogParserPath = fso.GetFile(LogParserPath).ShortPath
 
dot = InStr(SourceFileName, ".")
basename = Left(SourceFileName, dot-1)
DestFileName.Copy SendToPath & "\" & basename & ".csv", True
wscript.echo SourceFileName & " copied to " & SendToPath & "\" & basename & ".csv"
Set objCSV = fso.OpenTextFile(SendtoPath & "\" & basename & ".csv", 1, False)
strNewContents = strHeader & VbCrLf & objCSV.ReadAll
objCSV.Close
Set objCSV = fso.CreateTextFile(SendtoPath & "\" & basename & ".csv", True)
objCSV.Write strNewContents
objCSV.Close
Set objCSV = Nothing
 
Set DestFileName = Nothing
 
Set objSQLCmd = fso.OpenTextFile(SQLCmdPath, 1, False)
strSQLCmd = objSQLCmd.ReadLine
objSQLCmd.Close
Set objSQLCmd = Nothing
 
strCommand = LogParserPath & " -i:CSV  -o:DATAGRID """ & strSQLCmd & """"
objShell.Run strCommand, 1, False
 
Set fso = nothing

Open in new window

Have you considered using the com object for logparser?  Port the code such as http://forums.iis.net/t/1153701.aspx to your needs.  Much better than shelling out.
Hey Rob, thanks a million for your response, just tested that code you provided me.  It ran through the first part of the script fine, it copied and moved the file and renamed it to my folders destination path but after that it threw-up on me.  Here's what it said:

Script:  c:\documents and settings\mypc\Desktop\test.vbs
Line:     50
Char:    1
Error:    Object doesn't support this property or method: 'objShell.Run'
Code:    800A01B6
Source: Microsoft VBScript runtime error

What I did was make it simple, I set all the my test folders up on the root of my C drive as shown below in the code snippet.


Set objDialog = CreateObject("UserAccounts.CommonDialog")
 
strHeader = "EVTTYPE,DATE,TIME,EVT,EVTID,STATUS,ACCOUNT,DOMAIN/USER,DC"
 
objDialog.Filter = "VBScript Scripts|*.vbs|All Files|*.*"
objDialog.FilterIndex = 1
objDialog.InitialDir = "c:\SCRIPTS"
intResult = objDialog.ShowOpen
 
If intResult = 0 Then
    Wscript.Quit
End If
 
Dim fso, DestFilename
Dim SourceFileName, Source, TopDestPath, basename, dot, SendtoPath
 
TopDestPath = "C:\SCRIPTS"
SendtoPath = "C:\FOLDERA"
LogParserPath = "C:\LOGPARSER.EXE"
SQLCmdPath = "C:\SQLCommand.txt"
 
Set fso = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Scripting.FileSystemObject")
 
Source = objDialog.FileName
SourceFileName = fso.GetFileName(Source)
Set DestFileName = fso.GetFile(Source)
LogParserPath = fso.GetFile(LogParserPath).ShortPath
 
dot = InStr(SourceFileName, ".")
basename = Left(SourceFileName, dot-1)
DestFileName.Copy SendToPath & "\" & basename & ".csv", True
wscript.echo SourceFileName & " copied to " & SendToPath & "\" & basename & ".csv"
Set objCSV = fso.OpenTextFile(SendtoPath & "\" & basename & ".csv", 1, False)
strNewContents = strHeader & VbCrLf & objCSV.ReadAll
objCSV.Close
Set objCSV = fso.CreateTextFile(SendtoPath & "\" & basename & ".csv", True)
objCSV.Write strNewContents
objCSV.Close
Set objCSV = Nothing
 
Set DestFileName = Nothing
 
Set objSQLCmd = fso.OpenTextFile(SQLCmdPath, 1, False)
strSQLCmd = objSQLCmd.ReadLine
objSQLCmd.Close
Set objSQLCmd = Nothing
 
strCommand = LogParserPath & " -i:CSV  -o:DATAGRID """ & strSQLCmd & """"
objShell.Run strCommand, 1, False
 
Set fso = nothing

Open in new window

DOH!  I created the Shell object wrong......this should work.

Rob.
Set objDialog = CreateObject("UserAccounts.CommonDialog")
 
strHeader = "EVTTYPE,DATE,TIME,EVT,EVTID,STATUS,ACCOUNT,DOMAIN/USER,DC"
 
objDialog.Filter = "VBScript Scripts|*.vbs|All Files|*.*"
objDialog.FilterIndex = 1
objDialog.InitialDir = "c:\SCRIPTS"
intResult = objDialog.ShowOpen
 
If intResult = 0 Then
    Wscript.Quit
End If
 
Dim fso, DestFilename
Dim SourceFileName, Source, TopDestPath, basename, dot, SendtoPath
 
TopDestPath = "C:\SCRIPTS"
SendtoPath = "C:\FOLDERA"
LogParserPath = "C:\LOGPARSER.EXE"
SQLCmdPath = "C:\SQLCommand.txt"
 
Set fso = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
 
Source = objDialog.FileName
SourceFileName = fso.GetFileName(Source)
Set DestFileName = fso.GetFile(Source)
LogParserPath = fso.GetFile(LogParserPath).ShortPath
 
dot = InStr(SourceFileName, ".")
basename = Left(SourceFileName, dot-1)
DestFileName.Copy SendToPath & "\" & basename & ".csv", True
wscript.echo SourceFileName & " copied to " & SendToPath & "\" & basename & ".csv"
Set objCSV = fso.OpenTextFile(SendtoPath & "\" & basename & ".csv", 1, False)
strNewContents = strHeader & VbCrLf & objCSV.ReadAll
objCSV.Close
Set objCSV = fso.CreateTextFile(SendtoPath & "\" & basename & ".csv", True)
objCSV.Write strNewContents
objCSV.Close
Set objCSV = Nothing
 
Set DestFileName = Nothing
 
Set objSQLCmd = fso.OpenTextFile(SQLCmdPath, 1, False)
strSQLCmd = objSQLCmd.ReadLine
objSQLCmd.Close
Set objSQLCmd = Nothing
 
strCommand = LogParserPath & " -i:CSV  -o:DATAGRID """ & strSQLCmd & """"
objShell.Run strCommand, 1, False
 
Set fso = nothing

Open in new window

Hi Alan,

    With the code shown above, where would you place your solution at?  It looks as if it's geared more for webserver parse rather than what i'm needing above, I could be wrong, perhaps you could clarify it for me.  Sort of let me know where everything in reference to your suggestion would fall iin my code and better yet the correct syntax for everything to start working as I'm needing it to.
Hey Rob, went through smoothly that time.  For my SQLCommand.txt file I'm assuming that's the actual SQL statements that I will write for logparser?  When I go to folder A to and open the .CSV file it's pulling up everything.  For example, If I told SQLcommand.txt to:

logparser.exe -i:CSV -o:DATAGRID "Select date,time From c:\foldera\test.csv"

You would think my output would be just the date and time in the datagrid box but i'm not getting a datagrid nor am I actually seeing an output file, unless of course I've just over-looked it.  Either way Rob I think we are just about to nip this in the bud, we are sooooooo close!
Let me rephrase that statement above.  I tested the script, changed my SQLCommand.txt file to read

logparser.exe -i:CSV -o:DATAGRID "Select date,time From c:\foldera\test.csv"

Ok from I execute the script, it goes through fine.  I open the test.csv file in Folder A and it's not showing just date and time in CSV it's showing the entire CSV.  I'm assuming the output is to that CSV correct?  If it's to the Datagrid, the Datagrid is not appearing for some reason.
Hope all that makes sense to you.  Damn we are so close!!!! I'm getting all excited...haha
Hmmm, it's kind of confusing....I haven't used LogParser before, but from what you've posted, you can run
logparser.exe -i:CSV -o:DATAGRID "Select date,time From c:\foldera\test.csv"

So, what I've done is assume (sorry if I'm wrong) that your SQLCommands.txt contains only the following, on one line:
Select date,time From c:\foldera\test.csv

Then, my script will read that line, and generate the command of
logparser.exe -i:CSV -o:DATAGRID "Select date,time From c:\foldera\test.csv"

for objShell.Run to run.

Is that the way it's supposed to work?  My assumption was that when the objShell.Run method ran the full command, it would show a DataGrid with the results.  But perhaps I'm wrong....from what you're saying, about opening the CSV file first, you run LogParser from *within* Excel?

Regards,

Rob.
Basically I'm hoping to get it to work like this:

1.)  Execute Script.
2.)  Search dialog opens.
3.)  I select the file that I need.
4.) Click Open.
5.) *** I believe this is where your script would come into play*** The script would then go out to the SQLCommand.txt file and depending on that SQL Statement would perform the necessary parse via Logparser.
6.) The results of that parse of course would reside in the .CSV file in Folder A.

Hopefully that will help shed a little light on it.  So far though what you've provided has been awesome!
Right now, I basically open up Logparser 2.2 on my system and run it separately.  This is done after I have ran the script that copies, moves, adds headers and renames it to a .CSV file.  My hope or goal is to consolidate this process into basically one click with the script being tied into LogParser.  
Ok after working with this the better part of today, I was finally able to get a little something something out of it.  However just need a few wee bit of adjustments to it to make it work fully to what i'm needing.  

This is where i'm getting stuck at and where I think it is croaking at.  I think I've got the input and output mixed up or something...perhaps someone could read the snippet below and offer some insight.

strInputFile = "c:\FOLDER B\TESTFILE.csv"
strOutputFile = "c:\FOLDER B\TESTFILE-RESULTS.CSV"
strQuery = "SELECT DATE, EVT FROM c:\FOLDER A\TESTFILE.CSV INTO
c:\FOLDER B\TESTFILE-RESULTS.CSV"
Set objDialog = CreateObject("UserAccounts.CommonDialog")
 
strHeader = 
 
"EVTTYPE,DATE,TIME,EVT,EVTID,STATUS,ACCOUNT,DOMAIN/USER,DC,EVTCHANGE,EVTDETA
 
ILS"
 
objDialog.Filter = "VBScript Scripts|*.vbs|All Files|*.*"
objDialog.FilterIndex = 1
objDialog.InitialDir = "c:\folder a"
intResult = objDialog.ShowOpen
 
If intResult = 0 Then
    Wscript.Quit
End If
 
Dim fso, DestFilename
Dim SourceFileName, Source, TopDestPath, basename, dot, SendtoPath
 
TopDestPath = "c:\folder a"
SendtoPath = "c:\folder b"
 
Set fso = CreateObject("Scripting.FileSystemObject")
Source = objDialog.FileName
SourceFileName = fso.GetFileName(Source)
Set DestFileName = fso.GetFile(Source)
 
dot = InStr(SourceFileName, ".")
basename = Left(SourceFileName, dot-1)
DestFileName.Copy SendToPath & "\" & basename & ".csv", True
wscript.echo SourceFileName & " copied to " & SendToPath & "\" & basename & 
 
".csv"
Set objCSV = fso.OpenTextFile(SendtoPath & "\" & basename & ".csv", 1, 
 
False)
strNewContents = strHeader & VbCrLf & objCSV.ReadAll
objCSV.Close
Set objCSV = fso.CreateTextFile(SendtoPath & "\" & basename & ".csv", True)
objCSV.Write strNewContents
objCSV.Close
Set objCSV = Nothing
 
Set fso = nothing
Set DestFileName = nothing
 
Dim oLogParser
Dim oInputFormat
Dim oOutputFormat
Dim strInputFile
Dim strOutputFile
Dim strQuery
 
Set oLogParser = CreateObject("MSUtil.LogQuery")
Set oInputFormat = CreateObject("MSUtil.LogQuery.CSVInputFormat")
Set oOutputFormat = CreateObject("MSUtil.LogQuery.CSVOutputFormat")
 
strInputFile = "c:\FOLDER B\TESTFILE.csv"
strOutputFile = "c:\FOLDER B\TESTFILE-RESULTS.CSV"
strQuery = "SELECT DATE, EVT FROM c:\FOLDER A\TESTFILE.CSV INTO 
c:\FOLDER B\TESTFILE-RESULTS.CSV"
 
strQuery = Replace(strQuery, "<infile>", strInputFile)
strQuery = Replace(strQuery, "<outfile>", strOutputFile)
 
oLogParser.ExecuteBatch strQuery, oInputFormat, oOutputFormat

Open in new window

Hi, what about doing this for your last part, where I've put <infile> and <outfile> into strQuery, enclosed in double-quotes, in case the file paths have spaces....

Regards,

Rob.
Set oLogParser = CreateObject("MSUtil.LogQuery")
Set oInputFormat = CreateObject("MSUtil.LogQuery.CSVInputFormat")
Set oOutputFormat = CreateObject("MSUtil.LogQuery.CSVOutputFormat")
 
strInputFile = "c:\FOLDER B\TESTFILE.csv"
strOutputFile = "c:\FOLDER B\TESTFILE-RESULTS.CSV"
strQuery = "SELECT DATE, EVT FROM ""<infile>"" INTO ""<outfile>"""
 
strQuery = Replace(strQuery, "<infile>", strInputFile)
strQuery = Replace(strQuery, "<outfile>", strOutputFile)
 
oLogParser.ExecuteBatch strQuery, oInputFormat, oOutputFormat

Open in new window

Hey good to see you back Rob.  Well I thought we might of had it with that last bit of code you provided, however it's choaking telling me the following when I execute it.

Script:   C:\Documents and Settings\mypc\Desktop\test.vbs
Line:      58
Char:     1
Error:     Error parsing query: The specified FROM-ENTITY ""c:\FOLDER B\test.csv is invalid
              [The filename, directory name, or volume label syntax is incorrect.]
Code:     8007007B
Source:  CLogQueryClass

That's really odd that it has
""c:\FOLDER B\test.csv

with two quotes at the start of the file path....

Would it work without the quotes?

Rob.
Set oLogParser = CreateObject("MSUtil.LogQuery")
Set oInputFormat = CreateObject("MSUtil.LogQuery.CSVInputFormat")
Set oOutputFormat = CreateObject("MSUtil.LogQuery.CSVOutputFormat")
 
strInputFile = "c:\FOLDER B\TESTFILE.csv"
strOutputFile = "c:\FOLDER B\TESTFILE-RESULTS.CSV"
strQuery = "SELECT DATE, EVT FROM <infile> INTO <outfile>"
 
strQuery = Replace(strQuery, "<infile>", strInputFile)
strQuery = Replace(strQuery, "<outfile>", strOutputFile)
 
oLogParser.ExecuteBatch strQuery, oInputFormat, oOutputFormat

Open in new window

It choaked with a different error that time:  Weird.

Script:  C:\Documents and Settings\mypc\Desktop\test.vbs
Line:     58
Char:     1
Error:     Error parsing query: Syntax Error: extra token(s) after query: 'B\TESTFILE-RESULTS.CSV'[SQL  
              query syntax invalid or unsupported.]
Code:    8007064F
Source: CLogQueryClass
Yeah, that's what I figured.....spaces are a problem! Oh wait! It's SQL....let's try single quotes....

Regards,

Rob.
Set oLogParser = CreateObject("MSUtil.LogQuery")
Set oInputFormat = CreateObject("MSUtil.LogQuery.CSVInputFormat")
Set oOutputFormat = CreateObject("MSUtil.LogQuery.CSVOutputFormat")
 
strInputFile = "c:\FOLDER B\TESTFILE.csv"
strOutputFile = "c:\FOLDER B\TESTFILE-RESULTS.CSV"
strQuery = "SELECT DATE, EVT FROM '<infile>' INTO '<outfile>'"
 
strQuery = Replace(strQuery, "<infile>", strInputFile)
strQuery = Replace(strQuery, "<outfile>", strOutputFile)
 
oLogParser.ExecuteBatch strQuery, oInputFormat, oOutputFormat

Open in new window

Hey Rob, got it to work with the below code:

What I had to do was create a folder on my C drive called LOGPARSERTEST2, in that folder resides LOGPARSERTEST2.VBS and TESTSCRIPT.CSV.  Ok using this code, the script was able to parse through using Logparser and produced a results file called TESTSCRIPTSRESULTS.CSV successfully with what I was needing.

Ok, now that we have tackled the script conversion through logparser, the last hurdle is getting it to work with the rest of the code.  I don't know if my logic is flawed within the code or not.  Perhaps you could look at it and see how we can get it to mesh well with the code below.

Error that I'm getting when I run this code:

Script:   C:\Documents and Settings\mypc\Desktop\logparsertest2.vbs
Line:     58
Char:     1
Error:     Error parsing query: Error opening files: Error opening File "C:\FOLDER A\logparsertest.csv":
              The system casnnot find the file specified [The system cannot find the file specified.]
Code:     8007002
Source:  CLogQueryClass

Here is the logic behind the script:  I'd like to be able to select a file in a FOLDER A, click open, this copies this file, adds a header to the file, moves the file to FOLDER B and converts it to a .CSV file.  At this point our code below would kick in and the script would read through the Logparser statement and parse the needed information into a results file.  

I can get both scripts to work but they have to be ran independantly of each other, it would be nice to consolidate this all in one script if at all possible.  

Here is the full code:
**************************
Set objDialog = CreateObject("UserAccounts.CommonDialog")
 
strHeader =

"EVTTYPE,DATE,TIME,EVT,EVTID,STATUS,ACCOUNT,DOMAIN/USER,DC,EVTCHANGE,EVTDETA

ILS"
 
objDialog.Filter = "VBScript Scripts|*.vbs|All Files|*.*"
objDialog.FilterIndex = 1
objDialog.InitialDir = "c:\FOLDER A"
intResult = objDialog.ShowOpen
 
If intResult = 0 Then
    Wscript.Quit
End If
 
Dim fso, DestFilename
Dim SourceFileName, Source, TopDestPath, basename, dot, SendtoPath
 
TopDestPath = "c:\FOLDER A"
SendtoPath = "c:\FOLDER B"
 
Set fso = CreateObject("Scripting.FileSystemObject")
Source = objDialog.FileName
SourceFileName = fso.GetFileName(Source)
Set DestFileName = fso.GetFile(Source)
 
dot = InStr(SourceFileName, ".")
basename = Left(SourceFileName, dot-1)
DestFileName.Copy SendToPath & "\" & basename & ".csv", True
wscript.echo SourceFileName & " copied to " & SendToPath & "\" & basename & 

".csv"
Set objCSV = fso.OpenTextFile(SendtoPath & "\" & basename & ".csv", 1,

False)
strNewContents = strHeader & VbCrLf & objCSV.ReadAll
objCSV.Close
Set objCSV = fso.CreateTextFile(SendtoPath & "\" & basename & ".csv", True)
objCSV.Write strNewContents
objCSV.Close
Set objCSV = Nothing
 
Set fso = nothing
Set DestFileName = nothing

Dim oLogParser
Dim oInputFormat
Dim oOutputFormat
Dim strInputFile
Dim strOutputFile
Dim strQuery

Set oLogParser = CreateObject("MSUtil.LogQuery")
Set oInputFormat = CreateObject("MSUtil.LogQuery.CSVInputFormat")
Set oOutputFormat = CreateObject("MSUtil.LogQuery.CSVOutputFormat")
 
strInputFile = "testscript.csv"
strOutputFile = "testscriptresults.csv"
strQuery = "Select DATE, TIME INTO <outfile> FROM <infile>"
 
strQuery = Replace(strQuery, "<infile>", strInputFile)
strQuery = Replace(strQuery, "<outfile>", strOutputFile)
 
oLogParser.ExecuteBatch strQuery, oInputFormat, oOutputFormat





Option Explicit
 
Dim oLogParser
Dim oInputFormat
Dim oOutputFormat
Dim strInputFile
Dim strOutputFile
Dim strQuery
 
Set oLogParser = CreateObject("MSUtil.LogQuery")
Set oInputFormat = CreateObject("MSUtil.LogQuery.CSVInputFormat")
Set oOutputFormat = CreateObject("MSUtil.LogQuery.CSVOutputFormat")
 
strInputFile = "testscript.csv"
strOutputFile = "testscriptresults.csv"
strQuery = "Select DATE, TIME INTO <outfile> FROM <infile>"
 
strQuery = Replace(strQuery, "<infile>", strInputFile)
strQuery = Replace(strQuery, "<outfile>", strOutputFile)
 
oLogParser.ExecuteBatch strQuery, oInputFormat, oOutputFormat

Open in new window

This is what I'd like to accomplish:

1.)  Select the file in Folder A. i.e.  Let's say I selected a file called "mylog.xxxx"

2.)  At this stage, the script copies, moves it to Folder B and adds specified headers and finally renames mylog.xxxx to mylog.csv so that Logparser can parse through it and pull the required parameters as set in script.
                 
3.)  Script would then produce a results file based off of Step 2  i.e. "mylog-results.csv"  where it would reside in Folder B.

strInputFile = "mylogs.csv"
strOutputFile = "mylog-results.csv"
strQuery = "Select DATE, TIME INTO <outfile> FROM <infile>"

That's basically it in a nutshell with what I'd want the script to accomplish and we'll be done with this ( :
                 

Does it work from your full code above (the one in the comments of ID: 23931212, not the code snippet)

if you just change this line:
strQuery = "Select DATE, TIME INTO <outfile> FROM <infile>"

to this
strQuery = "Select DATE, TIME INTO '<outfile>' FROM '<infile>'"

Regards,

Rob.
Hi Rob,

    Yep it works beautifully, the problem is though when I try and combine it with my original code it croaks.  So right now essentially, I have two separate working scripts that I need to combine into one and don't know how to go about it.

Here's what I'm wanting to do:

Set of Events for Script to Follow:

1.)  Select the file in Folder A. i.e.  Let's say I selected a file called "mylog.xxxx"

2.)  At this stage, the script copies, moves it to Folder B and adds specified headers and finally renames mylog.xxxx to mylog.csv so that Logparser can parse through it and pull the required parameters as set in script.
               
3.)  Script would then produce a results file based off of Step 2  i.e. "mylog-results.csv"  where it would reside in Folder B.

That's basically it in a nutshell with what I'd want the script to accomplish and we'll be done with this ( :

     Presently, I have two scripts and  I'm sure it's the logic within both of the scripts that when ran they do not mesh together and croak.   Simply put, I'd just like it to perform the above 3 steps.

     Rob first off I want to thank you for staying with me on this, that says a lot about your character, second off,  you get this to work the beer is on me man ( :
OK mate, first off, I don't mind sticking around. I hate to leave people with half finished solutions....

Secondly, try this out....I think I finally get it, and hopefully this works as designed!

Regards,

Rob.
Set objDialog = CreateObject("UserAccounts.CommonDialog")
 
strHeader = "EVTTYPE,DATE,TIME,EVT,EVTID,STATUS,ACCOUNT,DOMAIN/USER,DC,EVTCHANGE,EVTDETAILS"
 
TopDestPath = "c:\FOLDER A"
SendtoPath = "c:\FOLDER B"
 
objDialog.Filter = "VBScript Scripts|*.vbs|All Files|*.*"
objDialog.FilterIndex = 1
objDialog.InitialDir = TopDestPath
intResult = objDialog.ShowOpen
 
If intResult = 0 Then
    Wscript.Quit
End If
 
Dim fso, DestFilename
Dim SourceFileName, Source, TopDestPath, basename, dot, SendtoPath
 
Set fso = CreateObject("Scripting.FileSystemObject")
Source = objDialog.FileName
SourceFileName = fso.GetFileName(Source)
Set DestFileName = fso.GetFile(Source)
 
dot = InStr(SourceFileName, ".")
basename = Left(SourceFileName, dot-1)
' This keeps the full path of the new file in a variable
strNewCSVFile = SendtoPath & "\" & basename & ".csv"
DestFileName.Copy strNewFileName, True
wscript.echo SourceFileName & " copied to " strNewCSVFile
Set objCSV = fso.OpenTextFile(strNewCSVFile, 1, False)
strNewContents = strHeader & VbCrLf & objCSV.ReadAll
objCSV.Close
Set objCSV = fso.CreateTextFile(strNewCSVFile, True)
objCSV.Write strNewContents
objCSV.Close
Set objCSV = Nothing
 
Set fso = nothing
Set DestFileName = nothing
 
Dim oLogParser
Dim oInputFormat
Dim oOutputFormat
Dim strInputFile
Dim strOutputFile
Dim strQuery
 
Set oLogParser = CreateObject("MSUtil.LogQuery")
Set oInputFormat = CreateObject("MSUtil.LogQuery.CSVInputFormat")
Set oOutputFormat = CreateObject("MSUtil.LogQuery.CSVOutputFormat")
 
strInputFile = strNewCSVFile
strOutputFile = Left(strInputFile, Len(strInputFile) - 4 & "_Results" & Right(strIntputFile, 4)
strQuery = "Select DATE, TIME INTO '<outfile>' FROM '<infile>'"
 
strQuery = Replace(strQuery, "<infile>", strInputFile)
strQuery = Replace(strQuery, "<outfile>", strOutputFile)
 
oLogParser.ExecuteBatch strQuery, oInputFormat, oOutputFormat
MsgBox strInputFile & VbCrLf & "has been modified by LogParser and saved to" & VbCrLf & strOutputFile

Open in new window

Hey there Rob, well it looks as if the bit of code you had me try above failed and is returning this error:

Script:    C:\Documents and Settings\mypc\desktop\test.vbs
Line:      30
Char:     45
Error:     Expected end of statement
Code:    800A0401
Source: Microsoft VBScript compliation error
Oh DOH!  Sorry.....forgot an ampersand on Line 30....
Set objDialog = CreateObject("UserAccounts.CommonDialog")
 
strHeader = "EVTTYPE,DATE,TIME,EVT,EVTID,STATUS,ACCOUNT,DOMAIN/USER,DC,EVTCHANGE,EVTDETAILS"
 
TopDestPath = "c:\FOLDER A"
SendtoPath = "c:\FOLDER B"
 
objDialog.Filter = "VBScript Scripts|*.vbs|All Files|*.*"
objDialog.FilterIndex = 1
objDialog.InitialDir = TopDestPath
intResult = objDialog.ShowOpen
 
If intResult = 0 Then
    Wscript.Quit
End If
 
Dim fso, DestFilename
Dim SourceFileName, Source, TopDestPath, basename, dot, SendtoPath
 
Set fso = CreateObject("Scripting.FileSystemObject")
Source = objDialog.FileName
SourceFileName = fso.GetFileName(Source)
Set DestFileName = fso.GetFile(Source)
 
dot = InStr(SourceFileName, ".")
basename = Left(SourceFileName, dot-1)
' This keeps the full path of the new file in a variable
strNewCSVFile = SendtoPath & "\" & basename & ".csv"
DestFileName.Copy strNewFileName, True
wscript.echo SourceFileName & " copied to " & strNewCSVFile
Set objCSV = fso.OpenTextFile(strNewCSVFile, 1, False)
strNewContents = strHeader & VbCrLf & objCSV.ReadAll
objCSV.Close
Set objCSV = fso.CreateTextFile(strNewCSVFile, True)
objCSV.Write strNewContents
objCSV.Close
Set objCSV = Nothing
 
Set fso = nothing
Set DestFileName = nothing
 
Dim oLogParser
Dim oInputFormat
Dim oOutputFormat
Dim strInputFile
Dim strOutputFile
Dim strQuery
 
Set oLogParser = CreateObject("MSUtil.LogQuery")
Set oInputFormat = CreateObject("MSUtil.LogQuery.CSVInputFormat")
Set oOutputFormat = CreateObject("MSUtil.LogQuery.CSVOutputFormat")
 
strInputFile = strNewCSVFile
strOutputFile = Left(strInputFile, Len(strInputFile) - 4 & "_Results" & Right(strIntputFile, 4)
strQuery = "Select DATE, TIME INTO '<outfile>' FROM '<infile>'"
 
strQuery = Replace(strQuery, "<infile>", strInputFile)
strQuery = Replace(strQuery, "<outfile>", strOutputFile)
 
oLogParser.ExecuteBatch strQuery, oInputFormat, oOutputFormat
MsgBox strInputFile & VbCrLf & "has been modified by LogParser and saved to" & VbCrLf & strOutputFile

Open in new window

Man Rob I think u are so close to cracking this!  Ran the above bit of code and here's what I'm getting...I guess this is one of those questions you'll be able to add to your list most difficult perhaps?

Script:    C:\Documents and Settings\mypc\Desktop\test.vbs
Line:       54
Char:      96
Error:     Expected ')'
Code:     800A03EE
Source:  Microsoft VBScript compilation error
Oh sorry!  Another syntax error.....that's what I get for not testing....try this....

Regards,

Rob.
Set objDialog = CreateObject("UserAccounts.CommonDialog")
 
strHeader = "EVTTYPE,DATE,TIME,EVT,EVTID,STATUS,ACCOUNT,DOMAIN/USER,DC,EVTCHANGE,EVTDETAILS"
 
TopDestPath = "c:\FOLDER A"
SendtoPath = "c:\FOLDER B"
 
objDialog.Filter = "VBScript Scripts|*.vbs|All Files|*.*"
objDialog.FilterIndex = 1
objDialog.InitialDir = TopDestPath
intResult = objDialog.ShowOpen
 
If intResult = 0 Then
    Wscript.Quit
End If
 
Dim fso, DestFilename
Dim SourceFileName, Source, TopDestPath, basename, dot, SendtoPath
 
Set fso = CreateObject("Scripting.FileSystemObject")
Source = objDialog.FileName
SourceFileName = fso.GetFileName(Source)
Set DestFileName = fso.GetFile(Source)
 
dot = InStr(SourceFileName, ".")
basename = Left(SourceFileName, dot-1)
' This keeps the full path of the new file in a variable
strNewCSVFile = SendtoPath & "\" & basename & ".csv"
DestFileName.Copy strNewFileName, True
wscript.echo SourceFileName & " copied to " & strNewCSVFile
Set objCSV = fso.OpenTextFile(strNewCSVFile, 1, False)
strNewContents = strHeader & VbCrLf & objCSV.ReadAll
objCSV.Close
Set objCSV = fso.CreateTextFile(strNewCSVFile, True)
objCSV.Write strNewContents
objCSV.Close
Set objCSV = Nothing
 
Set fso = nothing
Set DestFileName = nothing
 
Dim oLogParser
Dim oInputFormat
Dim oOutputFormat
Dim strInputFile
Dim strOutputFile
Dim strQuery
 
Set oLogParser = CreateObject("MSUtil.LogQuery")
Set oInputFormat = CreateObject("MSUtil.LogQuery.CSVInputFormat")
Set oOutputFormat = CreateObject("MSUtil.LogQuery.CSVOutputFormat")
 
strInputFile = strNewCSVFile
strOutputFile = Left(strInputFile, Len(strInputFile) - 4) & "_Results" & Right(strIntputFile, 4)
strQuery = "Select DATE, TIME INTO '<outfile>' FROM '<infile>'"
 
strQuery = Replace(strQuery, "<infile>", strInputFile)
strQuery = Replace(strQuery, "<outfile>", strOutputFile)
 
oLogParser.ExecuteBatch strQuery, oInputFormat, oOutputFormat
MsgBox strInputFile & VbCrLf & "has been modified by LogParser and saved to" & VbCrLf & strOutputFile

Open in new window

Well crud...lol....almost but no cigar bro.  I've attached a visual so you can see where it's getting caught up at.
Error1.JPG
OK, I didn't get the variable name right during the file copy on line 29....Typo.....Try this, I've changed the way it copies the file a bit, anyway.

Regards,

Rob.
Set objDialog = CreateObject("UserAccounts.CommonDialog")
 
strHeader = "EVTTYPE,DATE,TIME,EVT,EVTID,STATUS,ACCOUNT,DOMAIN/USER,DC,EVTCHANGE,EVTDETAILS"
 
TopDestPath = "c:\FOLDER A"
SendtoPath = "c:\FOLDER B"
 
objDialog.Filter = "VBScript Scripts|*.vbs|All Files|*.*"
objDialog.FilterIndex = 1
objDialog.InitialDir = TopDestPath
intResult = objDialog.ShowOpen
 
If intResult = 0 Then
    Wscript.Quit
End If
 
Dim fso, DestFilename
Dim SourceFileName, Source, TopDestPath, basename, dot, SendtoPath
 
Set fso = CreateObject("Scripting.FileSystemObject")
SourceFileName = objDialog.FileName
 
basename = Mid(SourceFileName, InStrRev(SourceFileName, "\") + 1)
dot = InStrRev(basename, ".")
basename = Left(basename, dot-1)
' This keeps the full path of the new file in a variable
strNewCSVFile = SendtoPath & "\" & basename & ".csv"
'wscript.echo "Copying " & SourceFileName & " to " & strNewCSVFile
fso.CopyFile SourceFileName, strNewCSVFile, True
wscript.echo SourceFileName & " copied to " & strNewCSVFile
WScript.Quit
Set objCSV = fso.OpenTextFile(strNewCSVFile, 1, False)
strNewContents = strHeader & VbCrLf & objCSV.ReadAll
objCSV.Close
Set objCSV = fso.CreateTextFile(strNewCSVFile, True)
objCSV.Write strNewContents
objCSV.Close
Set objCSV = Nothing
 
Set fso = nothing
Set DestFileName = nothing
 
Dim oLogParser
Dim oInputFormat
Dim oOutputFormat
Dim strInputFile
Dim strOutputFile
Dim strQuery
 
Set oLogParser = CreateObject("MSUtil.LogQuery")
Set oInputFormat = CreateObject("MSUtil.LogQuery.CSVInputFormat")
Set oOutputFormat = CreateObject("MSUtil.LogQuery.CSVOutputFormat")
 
strInputFile = strNewCSVFile
strOutputFile = Left(strInputFile, Len(strInputFile) - 4) & "_Results" & Right(strIntputFile, 4)
strQuery = "Select DATE, TIME INTO '<outfile>' FROM '<infile>'"
 
strQuery = Replace(strQuery, "<infile>", strInputFile)
strQuery = Replace(strQuery, "<outfile>", strOutputFile)
 
oLogParser.ExecuteBatch strQuery, oInputFormat, oOutputFormat
MsgBox strInputFile & VbCrLf & "has been modified by LogParser and saved to" & VbCrLf & strOutputFile

Open in new window

Hey there Rob, I think you fixed the errors, didn't crap out on me this time and it did in fact bring over the output file to Folder B.  However, it's not according to the "strQuery = "SELECT DATE, TIME INTO '<outfile>' FROM '<infile>'" line it doesn't appear to be reading that in the Output file.  I've added screenshots for your viewing.  It also isn't adding the header's specified in strHeader = "EVTTYPE,DATE,TIME,EVT,EVTID,STATUS,ACCOUNT,DOMAIN/USER,DC,EVTCHANGE,EVTDETAILS"

Hopefully with these visuals it will help you a little.  Let me know if I can provide you with anything else that will assist you.  The Output file screenshot is direct output of your latest code above, you'll notice headers are not in place nor is the SQL argument followed for some reason.  

Thanks again for all your hard work man, you have no idea how much you are appreciated!

C-Drive-Architechture.JPG
CONTENTS-FOLDER-A.JPG
CONTENTS-FOLDER-B.JPG
OUTPUT-FILE.JPG
OK, I've got a bit of time now to install LogParser and see if I can get it working once and for all :-)

Back soon....

Rob.
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
So did you now want this to run the same query against all files in FOLDER A?  That can be done....

Regards,

Rob.
ABSOLUTELY AND COMPLETELY SATISFIED.  You sir are a GEM!  I ran the file, it read through the SQL script for Logparser and produced exactly what I was needing.  I can't say thank you enough Rob, you stuck with me and I couldn't be happier with the results.  Your persistance, dedication to fix my issue says tons about your character and If were in a position to give you more than 500 points because in my opinion what you've done here is worth well over that.  I can't say enough kind words to show my appreciation to all of your hard work.  It's refreshing to know there are people like you on EE and make belonging to this site worth it.
ABSOLUTELY AND POSITIVELY one of the best experiences working with an Expert on EE that I ever had in the 7 years I've been a member.  Rob you are a GEM.  Highly recommend this Expert to anyone needing VBScript help.  HIGHLY RECOMMEND!
Hey mate, thanks for your kindness....much appreciated!  Its gratitude like yours that makes me feel my work has been worth it.  This has been a fun one, and I learnt new techniques with the LogParser, so it's all good!

Regards,

Rob.