{"id":110,"date":"2009-03-10T15:39:28","date_gmt":"2009-03-10T19:39:28","guid":{"rendered":"http:\/\/www.dev-notes.com\/blog\/2009\/03\/10\/logging-windows-events-with-vbscript\/"},"modified":"2009-03-10T15:39:28","modified_gmt":"2009-03-10T19:39:28","slug":"logging-windows-events-with-vbscript","status":"publish","type":"post","link":"https:\/\/www.dev-notes.com\/blog\/2009\/03\/10\/logging-windows-events-with-vbscript\/","title":{"rendered":"Logging Windows events with VBScript"},"content":{"rendered":"<p>The VBScript code to perform the insertion into the event log is shown below.  Please note that the &#8220;event_type&#8221; input variable will only take the following three values, in upper case letters:<\/p>\n<ul>\n<li>&#8220;ERROR&#8221; &#8211; Use when logging a problem<\/li>\n<li>&#8220;WARN&#8221; &#8211; Use when logging a minor issue<\/li>\n<li>&#8220;INFO&#8221; &#8211; Use when logging miscellaneous information<\/li>\n<\/ul>\n<p>When we run the example code further below, we will find the log as seen here.<\/p>\n<p><img decoding=\"async\" src=\"images\/code_windowsEventLog.jpg\"><\/p>\n<p><b>Example Code<\/b><\/p>\n<pre class=\"code\">\n''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''\n' Description: This sample code demonstrates how to log information \n'       to the Windows application event log\n' Author: C. Peter Chen, http:\/\/dev-notes.com\n'\n' Note: Allowable event_type values:\n'         \"ERROR\" - Use when logging a problem\n'         \"WARN\"  - Use when logging a minor issue\n'         \"INFO\"  - Use when logging miscellaneous information\n'\n' Revision History:\n'\t1.0\t20090310\tOriginal release\n''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''\noption explicit\n\nsub logWindowsEventViewer(event_type, event_text)\n\tdim WshShell, tp\n\t\n\tselect case event_type\n\tcase \"ERROR\"\n\t\ttp = \"1\"\n\tcase \"WARN\"\n\t\ttp = \"2\"\n\tcase \"INFO\"\n\t\ttp = \"4\"\n\tcase else\n\t\ttp = \"0\"\n\tend select\n\n\tset WshShell = CreateObject(\"WScript.Shell\")\n\twshshell.Logevent tp, event_text\n\tset wshshell=nothing\nend sub\n\n' Usage example:\ndim event_type, event_text\nevent_type = \"ERROR\"\nevent_text = \"Application error: GUI crashed!\"\n\ncall logWindowsEventViewer(event_type, event_text)\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Using Windows Scripting Host (WSH), we can insert entries into the Windows application event log for later debugging or other purposes.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,26],"tags":[],"class_list":["post-110","post","type-post","status-publish","format-standard","hentry","category-vbscript","category-windows"],"_links":{"self":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/posts\/110","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/comments?post=110"}],"version-history":[{"count":0,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/posts\/110\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/media?parent=110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/categories?post=110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/tags?post=110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}