{"id":563,"date":"2022-10-05T16:01:54","date_gmt":"2022-10-05T16:01:54","guid":{"rendered":"https:\/\/eventlogxp.com\/blog\/?p=563"},"modified":"2022-10-05T16:01:54","modified_gmt":"2022-10-05T16:01:54","slug":"scripting-in-event-log-explorer","status":"publish","type":"post","link":"https:\/\/eventlogxp.com\/blog\/scripting-in-event-log-explorer\/","title":{"rendered":"Scripting in Event Log Explorer"},"content":{"rendered":"<p>Starting from version 5.1 Event Log Explorer comes with scripting support (scripting is implemented in the forensic and enterprise editions). Scrips help you automate many routine tasks and improve your performance.<\/p>\n<p>Scripting lets you can open logs, set filters, scan event views, remove specific events from a log view, export events and many more.<\/p>\n<p>The scripting language we use in Event Log Explorer is PascalScript (FastScript by FastReports). It is similar to Pascal language with some limitation. You can download our scripting reference at <a href=\"https:\/\/eventlogxp.com\/download\/elex_scripting.pdf\">https:\/\/eventlogxp.com\/download\/elex_scripting.pdf<\/a><\/p>\n<p>Some sample scripts are available in folder &#8220;C:\\ProgramData\\Event Log Explorer\\Scripts\\Samples\\&#8221;.<\/p>\n<p>In this article we will write a script that merges security event log files located in one folder and displays only Audit Failure events.<\/p>\n<p>Let\u2019s start. First you need to start Event Log Explorer (Forensic or Enterprise edition) 5.2 or higher.<\/p>\n<p>From the main menu select Script -&gt; Script Console. Now you can type your script.<\/p>\n<p>Consider that your log files are stored in C:\\LogList folder and security log file names start with &#8216;Sec&#8217;, e.g. &#8216;security-08-2022.evtx&#8217;.<\/p>\n<p>We have procedure <strong>GetFileList<\/strong> which returns list of files matching the specified mask. It copies the list into TStringList.<\/p>\n<p>To run this procedure, we have to create TStringList object first:<\/p>\n<pre>var\r\n  FileList : TStringList;\r\nbegin\r\n  \/\/create object FileList of TStringList class\r\n  FileList := TStringList.Create;\r\n\r\n  \/\/ fill FileList with file names from C:\\LogList \r\n  \/\/ which start with 'sec' and have evtx file extension\r\n  GetFileList('C:\\LogList\\sec*.evtx', FileList);\r\n\r\n  \/\/ display the content of FileList in the debug console\r\n  DebugOut(FileList.Text);\r\n\r\n  \/\/ always free objects you created\r\n  FileList.Free;\r\nend.<\/pre>\n<p>Since you have a list of logs to merge, you can use function CreateLogFileMerger to open your files in a merger. This function is a method of TSApp class. When you start Event Log Explorer, it automatically creates an TheApp object which is a single instance of TSApp class (you cannot create TSApp instances manually).<\/p>\n<p>You can use TheApp properties and methods to manage Event Log Explorer application.<\/p>\n<p>CreateLogFileMerger creates an event log view contain events from all event log files in the list and returns a new TSLogView object associated with the log view.<\/p>\n<p>The first parameter of this function is FileNames of TStringList class. It is the same list we got by GetFileList function, but CreateLogFileMerger requires full path of file names. So, we need to add &#8216;C:\\LogList\\&#8217; before every name in the list.<\/p>\n<p>Modifying the script as follows:<\/p>\n<pre>var\r\n  FileList : TStringList;\r\n<strong>  i : Integer;<\/strong>\r\nbegin\r\n  \/\/create object FileList of TStringList class\r\n  FileList := TStringList.Create;\r\n\r\n  \/\/ fill FileList with file names from C:\\LogList \r\n  \/\/ which start with 'sec' and have evtx file extension\r\n  GetFileList('C:\\LogList\\sec*.evtx', FileList);\r\n\r\n<strong>  \/\/ Converting every name to full path name<\/strong>\r\n<strong>  for i := 0 to FileList.Count-1 do<\/strong>\r\n<strong> \u00a0\u00a0 FileList[i] := 'C:\\LogList\\'+FileList[i];<\/strong>\r\n\r\n  \/\/ display the content of FileList in the debug console\r\n  DebugOut(FileList.Text);\r\n\r\n  \/\/ always free objects you created\r\n  FileList.Free;\r\nend.<\/pre>\n<p>It&#8217;s time to create the merger. Add Merger declaration:<\/p>\n<pre>var\r\n  Merger : TSLogView;<\/pre>\n<p>and Merger creation before FileList.Free:<\/p>\n<pre>Merger := TheApp.CreateLogFileMerger(FileList, True);<\/pre>\n<p>The second parameter of CreateLogFileMerger \u00a0defines if the script waits until all the logs are loaded or not. Since we want to filter the merger, we should wait.<\/p>\n<p>To filter the log view, we can access the EventFilter property of the TSLogView and call EventFilterApply method to apply the filter:<\/p>\n<pre>\/\/ Clear current filter first\r\n\r\nMerger.EventFilter.Clear;\r\n\r\n\/\/ Set filter to display Audit Failure events only\r\n\r\nMerger.EventFilter.EVT_AUDIT_FAILURE := True;\r\n\r\n\/\/ Apply the filter\r\n\r\nMerger.EventFilterApply;<\/pre>\n<p>The final script:<\/p>\n<pre>var\r\n  Merger : TSLogView;\r\n  FileList : TStringList;\r\n  i : Integer;\r\nbegin\r\n  FileList := TStringList.Create;\r\n  GetFileList('C:\\LogList\\sec*.evtx', FileList);\r\n  for i := 0 to FileList.Count-1 do\r\n \u00a0\u00a0 FileList[i] := 'C:\\LogList\\'+FileList[i];\r\n  Merger := TheApp.CreateLogFileMerger(FileList, True);\r\n  FileList.Free;\r\n  Merger.EventFilter.Clear;\r\n  Merger.EventFilter.EVT_AUDIT_FAILURE := True;\r\n  Merger.EventFilterApply;\r\nend.<\/pre>\n<p>That&#8217;s all. As you can see, Event Log Explorer provides powerful, but not hard to use scripting mechanism to automate your tasks. <a href=\"https:\/\/eventlogxp.com\/download.php\">Download Event Log Explorer (Forensic or Enterprise Edition)<\/a> and write your own event log scripts!<\/p>\n<a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-facebook nolightbox\" data-provider=\"facebook\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Facebook\" href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Feventlogxp.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F563&#038;t=Scripting%20in%20Event%20Log%20Explorer&#038;s=100&#038;p&#091;url&#093;=https%3A%2F%2Feventlogxp.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F563&#038;p&#091;images&#093;&#091;0&#093;=https%3A%2F%2Feventlogxp.com%2Fblog%2Fwp-content%2Fuploads%2F2022%2F10%2Fscripting1.jpg&#038;p&#091;title&#093;=Scripting%20in%20Event%20Log%20Explorer\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img alt=\"Facebook\" title=\"Share on Facebook\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none\" src=\"https:\/\/eventlogxp.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/facebook.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-twitter nolightbox\" data-provider=\"twitter\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Twitter\" href=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Feventlogxp.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F563&#038;text=Check%20this%20Event%20Log%20Explorer%20blog%20post\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img alt=\"twitter\" title=\"Share on Twitter\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none\" src=\"https:\/\/eventlogxp.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/twitter.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-reddit nolightbox\" data-provider=\"reddit\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Reddit\" href=\"https:\/\/www.reddit.com\/submit?url=https%3A%2F%2Feventlogxp.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F563&#038;title=Scripting%20in%20Event%20Log%20Explorer\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img alt=\"reddit\" title=\"Share on Reddit\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none\" src=\"https:\/\/eventlogxp.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/reddit.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-pinterest nolightbox\" data-provider=\"pinterest\" target=\"_blank\" rel=\"nofollow\" title=\"Pin it with Pinterest\" href=\"https:\/\/pinterest.com\/pin\/create\/button\/?url=https%3A%2F%2Feventlogxp.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F563&#038;media=https%3A%2F%2Feventlogxp.com%2Fblog%2Fwp-content%2Fuploads%2F2022%2F10%2Fscripting1.jpg&#038;description=Scripting%20in%20Event%20Log%20Explorer\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img alt=\"pinterest\" title=\"Pin it with Pinterest\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none\" src=\"https:\/\/eventlogxp.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/pinterest.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-linkedin nolightbox\" data-provider=\"linkedin\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Linkedin\" href=\"https:\/\/www.linkedin.com\/shareArticle?mini=true&#038;url=https%3A%2F%2Feventlogxp.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F563&#038;title=Scripting%20in%20Event%20Log%20Explorer\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img alt=\"linkedin\" title=\"Share on Linkedin\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none\" src=\"https:\/\/eventlogxp.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/linkedin.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-mail nolightbox\" data-provider=\"mail\" rel=\"nofollow\" title=\"Share by email\" href=\"mailto:?subject=Scripting%20in%20Event%20Log%20Explorer&#038;body=Check%20this%20Event%20Log%20Explorer%20blog%20post:%20https%3A%2F%2Feventlogxp.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F563\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px\"><img alt=\"mail\" title=\"Share by email\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none\" src=\"https:\/\/eventlogxp.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/mail.png\" \/><\/a>","protected":false},"excerpt":{"rendered":"<p>Starting from version 5.1 Event Log Explorer comes with scripting support (scripting is implemented in the forensic and enterprise editions). Scrips help you automate many routine tasks and improve your performance. Scripting lets you can open logs, set filters, scan event views, remove specific events from a log view, export events and many more. The scripting language we use in Event Log Explorer is PascalScript\u2026 <span class=\"read-more\"><a href=\"https:\/\/eventlogxp.com\/blog\/scripting-in-event-log-explorer\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":565,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[83],"tags":[84],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/eventlogxp.com\/blog\/wp-json\/wp\/v2\/posts\/563"}],"collection":[{"href":"https:\/\/eventlogxp.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eventlogxp.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eventlogxp.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/eventlogxp.com\/blog\/wp-json\/wp\/v2\/comments?post=563"}],"version-history":[{"count":2,"href":"https:\/\/eventlogxp.com\/blog\/wp-json\/wp\/v2\/posts\/563\/revisions"}],"predecessor-version":[{"id":566,"href":"https:\/\/eventlogxp.com\/blog\/wp-json\/wp\/v2\/posts\/563\/revisions\/566"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/eventlogxp.com\/blog\/wp-json\/wp\/v2\/media\/565"}],"wp:attachment":[{"href":"https:\/\/eventlogxp.com\/blog\/wp-json\/wp\/v2\/media?parent=563"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eventlogxp.com\/blog\/wp-json\/wp\/v2\/categories?post=563"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eventlogxp.com\/blog\/wp-json\/wp\/v2\/tags?post=563"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}