Advertisement
relay12

EVENTQUERY.vbs (XP SP2 version)

May 30th, 2021 (edited)
431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '********************************************************************
  2. '*
  3. '* Copyright (c) Microsoft Corporation. All rights reserved.
  4. '*
  5. '* Module Name:    EVENTQUERY.vbs
  6. '*
  7. '* Abstract:       Enables an administrator to query/view all existing
  8. '*                 events in a given event log(s).
  9. '*
  10. '*
  11. '********************************************************************
  12. ' Global declaration
  13. OPTION EXPLICIT
  14.  
  15. ON ERROR RESUME NEXT
  16. Err.Clear
  17.  
  18. '----------------------------------------------------------------
  19. ' Start of localization Content
  20. '----------------------------------------------------------------
  21.  
  22. ' the filter operators specified by the user
  23. CONST L_OperatorEq_Text                 = "eq"
  24. CONST L_OperatorNe_Text                 = "ne"
  25. CONST L_OperatorGe_Text                 = "ge"
  26. CONST L_OperatorLe_Text                 = "le"
  27. CONST L_OperatorGt_Text                 = "gt"
  28. CONST L_OperatorLt_Text                 = "lt"
  29.  
  30. ' the filters as given by the user
  31. CONST L_UserFilterDateTime_Text         = "datetime"
  32. CONST L_UserFilterType_Text             = "type"
  33. CONST L_UserFilterUser_Text             = "user"
  34. CONST L_UserFilterComputer_Text         = "computer"
  35. CONST L_UserFilterSource_Text           = "source"
  36. CONST L_UserFilterDateCategory_Text     = "category"
  37. CONST L_UserFilterId_Text               = "id"
  38.  
  39. ' Define default values
  40. CONST L_ConstDefaultFormat_Text         = "TABLE"
  41.  
  42. ' Define other format  values
  43. CONST L_Const_List_Format_Text          = "LIST"
  44. CONST L_Const_Csv_Format_Text           = "CSV"
  45.  
  46. ' the text displayed in columns when no output is obtained for display
  47. CONST L_TextNa_Text                     = "N/A"
  48. CONST L_TextNone_Text                   = "None"
  49.  
  50. ' the following texts are used while parsing the command-line arguments
  51. ' (passed as input to the function component.getArguments)
  52. CONST L_MachineName_Text                = "Server Name"
  53. CONST L_UserName_Text                   = "User Name"
  54. CONST L_UserPassword_Text               = "User Password"
  55. CONST L_Format_Text                     = "Format"
  56. CONST L_Range_Text                      = "Range"
  57. CONST L_Filter_Text                     = "Filter"
  58. CONST L_Log_Text                        = "Logname"
  59.  
  60. ' the column headers used in the output display
  61. CONST L_ColHeaderType_Text              = "Type"
  62. CONST L_ColHeaderDateTime_Text          = "Date Time"
  63. CONST L_ColHeaderSource_Text            = "Source"
  64. CONST L_ColHeaderCategory_Text          = "Category"
  65. CONST L_ColHeaderEventcode_Text         = "Event"
  66. CONST L_ColHeaderUser_Text              = "User"
  67. CONST L_ColHeaderComputerName_Text      = "ComputerName"
  68. CONST L_ColHeaderDesription_Text        = "Description"
  69.  
  70. ' variable use to  concatenate  the Localization Strings.
  71. ' Error Messages
  72. Dim UseCscriptErrorMessage
  73. Dim InvalidParameterErrorMessage
  74. Dim InvalidFormatErrorMessage
  75. Dim InvalidCredentialsForServerErrorMessage
  76. Dim InvalidCredentialsForUserErrorMessage
  77. Dim InvalidSyntaxErrorMessage
  78. Dim InvalidInputErrorMessage
  79. Dim InvalidORSyntaxInFilterErrorMessage
  80. Dim InvalidSyntaxMoreNoRepeatedErrorMessage
  81.  
  82. UseCscriptErrorMessage                   = L_UseCscript1_ErrorMessage & vbCRLF & _
  83.                                                L_UseCscript2_ErrorMessage & vbCRLF & vbCRLF & _
  84.                                            L_UseCscript3_ErrorMessage & vbCRLF & _
  85.                                                L_UseCscript4_ErrorMessage & vbCRLF & vbCRLF & _
  86.                                                L_UseCscript5_ErrorMessage
  87.  
  88. CONST L_HelpSyntax1_Message                    = "Type ""%1 /?"" for usage."
  89. CONST L_HelpSyntax2_Message                    = "Type ""%2 /?"" for usage."
  90.  
  91. CONST L_InvalidParameter1_ErrorMessage      = "ERROR: Invalid Argument/Option - '%1'."
  92. InvalidParameterErrorMessage                = L_InvalidParameter1_ErrorMessage & vbCRLF & L_HelpSyntax2_Message
  93.  
  94. CONST L_InvalidFormat1_ErrorMessage             = "ERROR: Invalid 'FORMAT' '%1' specified."
  95. InvalidFormatErrorMessage                       = L_InvalidFormat1_ErrorMessage  &  vbCRLF & L_HelpSyntax2_Message
  96.  
  97. CONST L_InvalidRange_ErrorMessage               = "ERROR: Invalid 'RANGE' '%1' specified."
  98. CONST L_Invalid_ErrorMessage                    = "ERROR: Invalid '%1'."
  99. CONST L_InvalidType_ErrorMessage                = "ERROR: Invalid 'TYPE' '%1' specified for the 'FILTER' '%2'."
  100. CONST L_InvalidUser_ErrorMessage                = "ERROR: Invalid 'USER' '%1' specified for the 'FILTER '%2'."
  101. CONST L_InvalidId_ErrorMessage                  = "ERROR: Invalid 'ID' '%1' specified for the 'FILTER' '%2'."
  102. CONST L_InvalidFilter_ErrorMessage              = "ERROR: Invalid 'FILTER' '%1' specified for the 'FILTER' '%2'."
  103. CONST L_InvalidFilterFormat_ErrorMessage        = "ERROR: The FILTER '%1' is not in the required format."
  104. CONST L_InvalidFilterOperation_ErrorMessage     = "ERROR: Invalid FILTER operator '%1' specified for the filter '%2'."
  105.  
  106. CONST  L_InvalidCredentialsForServer1_ErrorMessage   = "ERROR: Invalid Syntax. /U can be specified only when /S is specified."
  107. InvalidCredentialsForServerErrorMessage              = L_InvalidCredentialsForServer1_ErrorMessage  & vbCRLF & L_HelpSyntax1_Message
  108.  
  109. CONST  L_InvalidCredentialsForUser1_ErrorMessage = "ERROR: Invalid Syntax. /P can be specified only when /U is specified."
  110. InvalidCredentialsForUserErrorMessage            = L_InvalidCredentialsForUser1_ErrorMessage & vbCRLF & L_HelpSyntax1_Message
  111.  
  112. CONST L_InvalidOperator_ErrorMessage             = "ERROR: Invalid operator specified for the range of dates in the 'DATETIME' filter."
  113. CONST L_InvalidDateTimeFormat_ErrorMessage       = "ERROR: Invalid 'DATETIME' format specified. Format:mm/dd/yy(yyyy),hh:mm:ssAM(/PM)"
  114.  
  115. CONST L_ExecuteQuery_ErrorMessage               = "ERROR: Unable to execute the query for the '%1' log."
  116. CONST L_LogDoesNotExist_ErrorMessage            = "ERROR: The log file '%1' does not exist."
  117. CONST L_InstancesFailed_ErrorMessage            = "ERROR: Unable to get the log details from the system."    
  118.  
  119. CONST  L_InvalidSyntax1_ErrorMessage            = "ERROR: Invalid Syntax."
  120. InvalidSyntaxErrorMessage                       = L_InvalidSyntax1_ErrorMessage & vbCRLF &  L_HelpSyntax1_Message
  121.  
  122. CONST L_InvalidInput1_ErrorMessage              = "ERROR: Invalid input. Please check the input Values."
  123. InvalidInputErrorMessage                        = L_InvalidInput1_ErrorMessage & vbCRLF &  L_HelpSyntax1_Message
  124.  
  125. CONST  L_ObjCreationFail_ErrorMessage           = "ERROR: Unexpected Error , Query failed. "
  126. CONST L_InfoUnableToInclude_ErrorMessage        = "ERROR: Unable to include the common module""CmdLib.Wsc""."
  127. CONST L_NoHeaderaNotApplicable_ErrorMessage     = "ERROR: /NH option is allowed only for ""TABLE"" and ""CSV"" formats."
  128. CONST L_InValidServerName_ErrorMessage          = "ERROR: Invalid Syntax. System name cannot be empty."
  129. CONST L_InValidUserName_ErrorMessage            = "ERROR: Invalid Syntax. User name cannot be empty. "
  130.  
  131. CONST  L_InvalidORSyntaxInFilter1_ErrorMessage  = "ERROR: Invalid 'OR' operation is specified for the filter."
  132. CONST  L_InvalidORSyntaxInFilter2_ErrorMessage  = "'OR' operation valid only for filters TYPE and ID."      
  133. InvalidORSyntaxInFilterErrorMessage             = L_InvalidORSyntaxInFilter1_ErrorMessage & vbCRLF & L_InvalidORSyntaxInFilter2_ErrorMessage
  134.  
  135. CONST  L_InvalidSyntaxMoreNoRepeated1_ErrorMessage = "ERROR: Invalid Syntax. '%1' option is not allowed more than 1 time(s)."
  136. InvalidSyntaxMoreNoRepeatedErrorMessage            = L_InvalidSyntaxMoreNoRepeated1_ErrorMessage  & vbCRLF &  L_HelpSyntax2_Message  
  137.  
  138. '  Hints given in case of errors
  139. CONST L_HintCheckConnection_Message           = "ERROR: Please check the system name, credentials and WBEM Core."
  140.  
  141. ' Informational messages
  142. CONST L_InfoNoRecordsInFilter_Message         = "INFO: No records available for the '%1' log with the specified criteria."
  143. CONST L_InfoNoRecords_Message                 = "INFO: No records available for the '%1' log."
  144. CONST L_InfoNoLogsPresent_Message             = "INFO: No logs are available in the system."
  145. CONST L_InfoDisplayLog_Message                = "Listing the events in '%1' log of host '%2'"
  146.  
  147. ' Cscript usage strings
  148. CONST L_UseCscript1_ErrorMessage    = "This script should be executed from the Command Prompt using CSCRIPT.EXE."
  149. CONST L_UseCscript2_ErrorMessage    = "For example: CSCRIPT EVENTQUERY.vbs <arguments>"
  150. CONST L_UseCscript3_ErrorMessage    = "To set CScript as the default application to run .vbs files run the following"
  151. CONST L_UseCscript4_ErrorMessage    = "       CSCRIPT //H:CSCRIPT //S"
  152. CONST L_UseCscript5_ErrorMessage    = "You can then run ""EVENTQUERY.vbs <arguments>"" without preceding the script with CSCRIPT."
  153.  
  154. ' Contents for showing help for Usage
  155. CONST L_ShowUsageLine00_Text            = "No logs are available on this system for query."
  156. CONST L_ShowUsageLine01_Text            = "EVENTQUERY.vbs [/S system [/U username [/P password]]] [/FI filter]"
  157. CONST L_ShowUsageLine02_Text            = "               [/FO format] [/R range] [/NH] [/V] [/L logname | *]"
  158. CONST L_ShowUsageLine03_Text            = "Description:"
  159. CONST L_ShowUsageLine04_Text            = "    The EVENTQUERY.vbs script enables an administrator to list"
  160. CONST L_ShowUsageLine05_Text            = "    the events and event properties from one or more event logs."
  161. CONST L_ShowUsageLine06_Text            = "Parameter List:"
  162. CONST L_ShowUsageLine07_Text            = "    /S     system          Specifies the remote system to connect to."
  163. CONST L_ShowUsageLine08_Text            = "    /U     [domain\]user   Specifies the user context under which the"
  164. CONST L_ShowUsageLine09_Text            = "                           command should execute."
  165. CONST L_ShowUsageLine10_Text            = "    /P     password        Specifies the password for the given"
  166. CONST L_ShowUsageLine11_Text            = "                           user context."
  167. CONST L_ShowUsageLine12_Text            = "    /V                     Specifies that the detailed information"
  168. CONST L_ShowUsageLine13_Text            = "                           should be displayed in the output."
  169. CONST L_ShowUsageLine14_Text            = "    /FI    filter          Specifies the types of events to"
  170. CONST L_ShowUsageLine15_Text            = "                           filter in or out of the query."
  171. CONST L_ShowUsageLine16_Text            = "    /FO    format          Specifies the format in which the output"
  172. CONST L_ShowUsageLine17_Text            = "                           is to be displayed."
  173. CONST L_ShowUsageLine18_Text            = "                           Valid formats are ""TABLE"", ""LIST"", ""CSV""."
  174. CONST L_ShowUsageLine19_Text            = "    /R     range           Specifies the range of events to list."
  175. CONST L_ShowUsageLine20_Text            = "                           Valid Values are:"
  176. CONST L_ShowUsageLine21_Text            = "                               'N' - Lists 'N' most recent events."
  177. CONST L_ShowUsageLine22_Text            = "                              '-N' - Lists 'N' oldest events."
  178. CONST L_ShowUsageLine23_Text            = "                           'N1-N2' - Lists the events N1 to N2."
  179. CONST L_ShowUsageLine24_Text            = "    /NH                    Specifies that the ""Column Header"" should"
  180. CONST L_ShowUsageLine25_Text            = "                           not be displayed in the output."
  181. CONST L_ShowUsageLine26_Text            = "                           Valid only for ""TABLE"" and ""CSV"" formats."
  182. CONST L_ShowUsageLine27_Text            = "    /L     logname         Specifies the log(s) to query."
  183. CONST L_ShowUsageLine28_Text            = "    /?                     Displays this help/usage."
  184. CONST L_ShowUsageLine29_Text            = "    Valid Filters  Operators allowed   Valid Values"
  185. CONST L_ShowUsageLine30_Text            = "    -------------  ------------------  ------------"
  186. CONST L_ShowUsageLine31_Text            = "    DATETIME       eq,ne,ge,le,gt,lt   mm/dd/yy(yyyy),hh:mm:ssAM(/PM)"
  187. CONST L_ShowUsageLine32_Text            = "    TYPE           eq,ne               ERROR, INFORMATION, WARNING,"
  188. CONST L_ShowUsageLine33_Text            = "                                       SUCCESSAUDIT, FAILUREAUDIT"
  189. CONST L_ShowUsageLine34_Text            = "    ID             eq,ne,ge,le,gt,lt   non-negative integer"
  190. CONST L_ShowUsageLine35_Text            = "    USER           eq,ne               string"
  191. CONST L_ShowUsageLine36_Text            = "    COMPUTER       eq,ne               string"
  192. CONST L_ShowUsageLine37_Text            = "    SOURCE         eq,ne               string"
  193. CONST L_ShowUsageLine38_Text            = "    CATEGORY       eq,ne               string"
  194. CONST L_ShowUsageLine39_Text            = "NOTE: Filter ""DATETIME"" can be specified as ""FromDate-ToDate"""
  195. CONST L_ShowUsageLine40_Text            = "      Only ""eq"" operator can be used for this format."
  196. CONST L_ShowUsageLine41_Text            = "Examples:"
  197. CONST L_ShowUsageLine42_Text            = "    EVENTQUERY.vbs "
  198. CONST L_ShowUsageLine43_Text            = "    EVENTQUERY.vbs /L system  "
  199. CONST L_ShowUsageLine44_Text            = "    EVENTQUERY.vbs /S system /U user /P password /V /L *"
  200. CONST L_ShowUsageLine45_Text            = "    EVENTQUERY.vbs /R 10 /L Application /NH"
  201. CONST L_ShowUsageLine46_Text            = "    EVENTQUERY.vbs /R -10 /FO LIST /L Security"
  202. CONST L_ShowUsageLine47_Text            = "    EVENTQUERY.vbs /R 5-10 /L ""DNS Server"""
  203. CONST L_ShowUsageLine48_Text            = "    EVENTQUERY.vbs /FI ""Type eq Error"" /L Application"
  204. CONST L_ShowUsageLine49_Text            = "    EVENTQUERY.vbs /L Application"
  205. CONST L_ShowUsageLine50_Text            = "            /FI ""Datetime eq 06/25/00,03:15:00AM-06/25/00,03:15:00PM"""
  206. CONST L_ShowUsageLine51_Text            = "    EVENTQUERY.vbs /FI ""Datetime gt 08/03/00,06:20:00PM"" "
  207. CONST L_ShowUsageLine52_Text            = "            /FI ""Id gt 700"" /FI ""Type eq warning"" /L System"
  208. CONST L_ShowUsageLine53_Text            = "    EVENTQUERY.vbs /FI ""Type eq error OR Id gt 1000 """
  209. '-------------------------------------------------------------------------
  210. ' END of localization content
  211. '-------------------------------------------------------------------------
  212.  
  213. ' Define constants
  214. CONST CONST_ERROR                 = 0
  215. CONST CONST_CSCRIPT               = 2
  216. CONST CONST_SHOW_USAGE            = 3
  217. CONST CONST_PROCEED               = 4
  218. CONST CONST_ERROR_USAGE           = 5
  219. CONST CONST_NO_MATCHES_FOUND      = 0
  220.  
  221. ' Define the Exit Values
  222. CONST EXIT_SUCCESS                = 0
  223. CONST EXIT_UNEXPECTED             = 255
  224. CONST EXIT_INVALID_INPUT          = 254
  225. CONST EXIT_METHOD_FAIL            = 250
  226. CONST EXIT_INVALID_PARAM          = 999
  227. CONST EXIT_INVALID_PARAM_DEFAULT_OPTION_REPEATED = 777
  228.  
  229. ' Define default values
  230. CONST CONST_ARRAYBOUND_NUMBER     = 10
  231. CONST CONST_ID_NUMBER             = 65535
  232.  
  233. ' Define namespace and class names of wmi
  234. CONST CONST_NAMESPACE_CIMV2       = "root\cimv2"
  235. CONST CLASS_EVENTLOG_FILE         = "Win32_NTEventlogFile"
  236.  
  237. ' for blank line in  help usage  
  238. CONST EmptyLine_Text          = " "
  239.  
  240. ' Define the various strings used in the script
  241. '=============================================
  242. ' the valid options supported by the script
  243. CONST OPTION_SERVER               = "s"
  244. CONST OPTION_USER                 = "u"
  245. CONST OPTION_PASSWORD             = "p"
  246. CONST OPTION_FORMAT               = "fo"
  247. CONST OPTION_RANGE                = "r"
  248. CONST OPTION_NOHEADER             = "nh"
  249. CONST OPTION_VERBOSE              = "v"
  250. CONST OPTION_FILTER               = "fi"
  251. CONST OPTION_HELP                 = "?"
  252. CONST OPTION_LOGNAME              = "l"
  253.  
  254. ' the property names on which the user given filters are applied
  255. CONST FLD_FILTER_DATETIME         = "TimeGenerated"
  256. CONST FLD_FILTER_TYPE             = "Type"
  257. CONST FLD_FILTER_USER             = "User"
  258. CONST FLD_FILTER_COMPUTER         = "ComputerName"
  259. CONST FLD_FILTER_SOURCE           = "SourceName"
  260. CONST FLD_FILTER_CATEGORY         = "CategoryString"
  261. CONST FLD_FILTER_ID               = "EventCode"
  262. CONST FLD_FILTER_EVENTTYPE        = "EventType"
  263.  
  264. ' Define matching patterns used in validations
  265. CONST PATTERNFORMAT              = "^(table|list|csv)$"
  266. CONST PATTERNTYPE                = "^(ERROR|INFORMATION|WARNING|SUCCESSAUDIT|FAILUREAUDIT)$"
  267.  
  268. ' Property values on which the user is given for the filter TYPE is applied  
  269. CONST PATTERNTYPE_ERROR           = "ERROR"
  270. CONST PATTERNTYPE_WARNING         = "WARNING"
  271. CONST PATTERNTYPE_INFORMATION     = "INFORMATION"
  272. CONST PATTERNTYPE_SUCCESSAUDIT    = "SUCCESSAUDIT"
  273. CONST PATTERNTYPE_FAILUREAUDIT    = "FAILUREAUDIT"
  274.  
  275. CONST FLDFILTERTYPE_SUCCESSAUDIT       = "audit success"
  276. CONST FLDFILTERTYPE_FAILUREAUDIT        = "audit failure"
  277.  
  278. ' Define EventType
  279. CONST EVENTTYPE_ERROR             = "1"
  280. CONST EVENTTYPE_WARNING           = "2"
  281. CONST EVENTTYPE_INFORMATION       = "3"
  282. CONST EVENTTYPE_SUCCESSAUDIT      = "4"
  283. CONST EVENTTYPE_FAILUREAUDIT      = "5"
  284.  
  285. ' the operator symbols
  286. CONST SYMBOL_OPERATOR_EQ          = "="
  287. CONST SYMBOL_OPERATOR_NE          = "<>"
  288. CONST SYMBOL_OPERATOR_GE          = ">="
  289. CONST SYMBOL_OPERATOR_LE          = "<="
  290. CONST SYMBOL_OPERATOR_GT          = ">"
  291. CONST SYMBOL_OPERATOR_LT          = "<"
  292.  
  293. ' Define matching patterns used in validations
  294. CONST PATTERN_RANGE               = "^\d*-?\d+$"
  295. CONST PATTERN_FILTER              = "^([a-z]+)([\s]+)([a-z]+)([\s]+)([\w+]|[\W+]|\\)"
  296. CONST PATTERN_DATETIME            = "^\d{1,2}\/\d{1,2}\/\d{2,4},\d{1,2}:\d{1,2}:\d{1,2}(A|P)M$"
  297. CONST PATTERN_INVALID_USER        = "\|\[|\]|\:|\||\<|\>|\+|\=|\;|\,|\?|\*"
  298. CONST PATTERN_ID                  = "^(\d+)$"
  299. CONST PATTERN_DATETIME_RANGE      = "^\d{1,2}\/\d{1,2}\/\d{2,4},\d{1,2}:\d{1,2}:\d{1,2}(A|P)M\-\d{1,2}\/\d{1,2}\/\d{2,4},\d{1,2}:\d{1,2}:\d{1,2}(A|P)M$"
  300.  
  301. ' Define  UNC  format for server name  
  302. CONST   UNC_Format_Servername     = "\\"
  303.  
  304. ' Define  const for  filter  separation when OR is specified in filter
  305. CONST L_OperatorOR_Text           = " OR "
  306.  
  307. ' Variable to trap local if already connection in wmiconnect function
  308. Dim blnLocalConnection  
  309.  
  310.  blnLocalConnection = False 'defalut value
  311.  
  312. ' to include the common module
  313. Dim component                ' object to store  common module  
  314.  
  315. Set component = CreateObject( "Microsoft.CmdLib" )
  316.  
  317. If Err.Number Then
  318.     WScript.Echo(L_InfoUnableToInclude_ErrorMessage)
  319.     WScript.Quit(EXIT_METHOD_FAIL)
  320. End If
  321.  
  322. ' referring the script host to common module
  323. Set component.ScriptingHost = WScript.Application
  324.  
  325. ' Check whether the script is run using CScript
  326. If CInt( component.checkScript() ) <> CONST_CSCRIPT Then
  327.         WScript.Echo (UseCscriptErrorMessage)
  328.         WScript.Quit(EXIT_UNEXPECTED)
  329. End If
  330.  
  331. ' Calling the Main function
  332. Call VBMain()  
  333.  
  334. ' end of the Main  
  335. Wscript.Quit(EXIT_SUCCESS)
  336.  
  337.  
  338. '********************************************************************
  339. '* Sub: VBMain
  340. '*
  341. '* Purpose: This is main function to starts execution
  342. '*
  343. '*
  344. '* Input/ Output: None
  345. '********************************************************************
  346. Sub VBMain()
  347.  
  348. ON ERROR RESUME NEXT
  349. Err.clear
  350.  
  351. ' Declare variables
  352. Dim intOpCode               ' to check the operation asked for, Eg:Help etc
  353. Dim strMachine              ' the machine to query the events from
  354. Dim strUserName             ' the user name to use to query the machine
  355. Dim strPassword             ' the password for the user to query the machine
  356. Dim strFormat               ' format of display, default is table
  357. Dim strRange                ' to store the range of records specified
  358. Dim blnNoHeader             ' flag to store if header is not required
  359. Dim blnVerboseDisplay       ' flag to verify if verbose display is needed
  360. ReDim arrFilters(5)         ' to store all the given filters
  361. Dim objLogs                 ' a object to store all the given logfles
  362.  
  363. ' Initialize variables
  364. intOpCode            = 0
  365. strFormat            = L_ConstDefaultFormat_Text
  366. strRange             = ""
  367. blnNoHeader          = FALSE
  368. blnVerboseDisplay    = FALSE
  369.  
  370. Set objLogs = CreateObject("Scripting.Dictionary")
  371.  
  372. If Err.Number Then
  373.     WScript.Echo (L_ObjCreationFail_ErrorMessage)
  374.     WScript.Quit(EXIT_METHOD_FAIL)
  375. End If  
  376.  
  377. ' setting Dictionary object compare mode to VBBinaryCompare
  378. objLogs.CompareMode = VBBinaryCompare
  379.  
  380. ' Parse the command line
  381. intOpCode = intParseCmdLine(strMachine, _
  382.                             strUserName, _
  383.                             strPassword, _
  384.                             arrFilters, _
  385.                             strFormat, _
  386.                             strRange, _
  387.                             blnVerboseDisplay, _
  388.                             blnNoHeader, _
  389.                             objLogs)
  390.  
  391.   If Err.number then
  392.     ' error in parsing the Command line
  393.     component.vbPrintf InvalidInputErrorMessage ,Array(Ucase(Wscript.ScriptName))
  394.     WScript.Quit(EXIT_UNEXPECTED)
  395.   End If
  396.  
  397. ' check the operation specified by the user
  398. Select Case intOpCode
  399.  
  400.     Case CONST_SHOW_USAGE
  401.         ' help asked for
  402.        Call ShowUsage()
  403.  
  404.     Case CONST_PROCEED
  405.         Call ShowEvents(strMachine, strUserName, strPassword, _
  406.             arrFilters, strFormat, strRange, _
  407.             blnVerboseDisplay, blnNoHeader, objLogs)
  408.             ' completed successfully
  409.            WScript.Quit(EXIT_SUCCESS)
  410.  
  411.     Case CONST_ERROR
  412.         ' print common help message.  
  413.        component.vbPrintf L_HelpSyntax1_Message, Array(Ucase(Wscript.ScriptName))
  414.         Wscript.Quit(EXIT_INVALID_INPUT)
  415.  
  416.     Case CONST_ERROR_USAGE
  417.         ' help is asked help with some other parameters
  418.        component.vbPrintf InvalidSyntaxErrorMessage, Array(Ucase(Wscript.ScriptName))
  419.         WScript.Quit(EXIT_INVALID_INPUT)
  420.  
  421.     Case EXIT_INVALID_PARAM_DEFAULT_OPTION_REPEATED
  422.             'More no of times  input values  specified.message is captured  at parser level so exit only with code.
  423.            Wscript.Quit(EXIT_INVALID_PARAM)
  424.  
  425.     Case Else
  426.             'Invalid input values specified.
  427.            component.vbPrintf InvalidSyntaxErrorMessage, Array(Ucase(Wscript.ScriptName))
  428.             Wscript.Quit(EXIT_INVALID_PARAM)
  429.  
  430. End Select
  431.  
  432. End Sub
  433. '***************************  End of Main  **************************
  434.  
  435. '********************************************************************
  436. '* Function: intParseCmdLine
  437. '*
  438. '* Purpose:  Parses the command line arguments to the variables
  439. '*
  440. '* Input:    
  441. '*  [out]    strMachine         machine to query events from
  442. '*  [out]    strUserName        user name to connect to the machine
  443. '*  [out]    strPassword        password for the user
  444. '*  [out]    arrFilters         the array containing the filters
  445. '*  [out]    strFormat          the display format
  446. '*  [out]    strRange           the range of records required
  447. '*  [out]    blnVerboseDisplay  flag to verify if verbose display is needed
  448. '*  [out]    blnNoHeader        flag to verify if noheader display is needed  
  449. '*  [out]    objLogs             to store all the given logfles
  450. '* Output:   Returns CONST_PROCEED, CONST_SHOW_USAGE or CONST_ERROR
  451. '*           Displays error message and quits if invalid option is asked
  452. '*
  453. '********************************************************************
  454. Private Function intParseCmdLine( ByRef strMachine,      _
  455.                                   ByRef strUserName,     _
  456.                                   ByRef strPassword,     _
  457.                                   ByRef arrFilters,      _
  458.                                   ByRef strFormat,       _
  459.                                   ByRef strRange,        _
  460.                                   ByRef blnVerboseDisplay, _
  461.                                   ByRef blnNoHeader,_
  462.                                   ByRef objLogs)
  463.  
  464.     ON ERROR RESUME NEXT
  465.     Err.Clear
  466.  
  467.     Dim strUserGivenArg ' to temporarily store the user given arguments to script
  468.    Dim strTemp         ' to store temporary values
  469.    Dim intArgIter      ' to count the number of arguments given by user
  470.    Dim intArgLogType   ' to count number of log files specified - Used in ReDim
  471.    Dim intFilterCount  ' to count number of filters specified - Used in ReDim
  472.  
  473.     Dim blnHelp         ' to check if already Help is specified  
  474.    Dim blnFormat       ' to check if  already Format is specified  
  475.    Dim blnRange        ' to check if already Range is specified  
  476.    Dim blnServer       ' to check if already Server is specified  
  477.    Dim blnPassword     ' to check if already Password is specified  
  478.    Dim blnUser     ' to check if already User is specified  
  479.  
  480.     strUserGivenArg  = ""
  481.     intArgLogType    = 0
  482.     intFilterCount   = 0
  483.     intArgIter       = 0
  484.  
  485.     'default values  
  486.    blnHelp         =  False
  487.     blnPassword   =  False
  488.     blnUser         =  False
  489.     blnServer        =  False
  490.     blnFormat      =  False
  491.  
  492.  
  493.     ' Retrieve the command line and set appropriate variables
  494. Do While intArgIter <= Wscript.arguments.Count - 1
  495.      strUserGivenArg = Wscript.arguments.Item(intArgIter)
  496.  
  497.  IF   Left( strUserGivenArg,1) = "/"  OR    Left( strUserGivenArg,1) = "-"  Then
  498.          strUserGivenArg = Right( strUserGivenArg,Len(strUserGivenArg) -1 )
  499.  
  500.         Select Case LCase(strUserGivenArg)
  501.             Case LCase(OPTION_SERVER)
  502.  
  503.                     'If more than  1 time(s) is spcecified
  504.                If  blnServer  =True   Then
  505.                   component.vbPrintf InvalidSyntaxMoreNoRepeatedErrorMessage, Array(Wscript.arguments.Item(intArgIter), Ucase(Wscript.ScriptName))
  506.                 intParseCmdLine = EXIT_INVALID_PARAM_DEFAULT_OPTION_REPEATED
  507.                 Exit Function
  508.                 End If
  509.  
  510.             If Not component.getArguments(L_MachineName_Text, strMachine, intArgIter, FALSE) Then
  511.                 intParseCmdLine = CONST_ERROR
  512.                 Exit Function
  513.             End If
  514.  
  515.             blnServer  =True
  516.                 intArgIter = intArgIter + 1
  517.  
  518.             Case LCase(OPTION_USER)
  519.  
  520.                     'If more than  1 time(s) is spcecified
  521.                If  blnUser  =True   Then
  522.                  component.vbPrintf InvalidSyntaxMoreNoRepeatedErrorMessage, Array(Wscript.arguments.Item(intArgIter), Ucase(Wscript.ScriptName))
  523.                 intParseCmdLine = EXIT_INVALID_PARAM_DEFAULT_OPTION_REPEATED
  524.                 Exit Function
  525.                 End If
  526.  
  527.             If Not component.getArguments(L_UserName_Text, strUserName, intArgIter, FALSE) Then
  528.                 intParseCmdLine = CONST_ERROR
  529.                 Exit Function
  530.             End If
  531.            
  532.             blnUser  =True
  533.                 intArgIter = intArgIter + 1
  534.  
  535.             Case LCase(OPTION_PASSWORD)
  536.  
  537.                     'If more than  1 time(s) is spcecified
  538.                    If  blnPassword  =True   Then
  539.                  component.vbPrintf InvalidSyntaxMoreNoRepeatedErrorMessage, Array(Wscript.arguments.Item(intArgIter), Ucase(Wscript.ScriptName))
  540.                 intParseCmdLine = EXIT_INVALID_PARAM_DEFAULT_OPTION_REPEATED
  541.                 Exit Function
  542.              End If
  543.  
  544.             If Not component.getArguments(L_UserPassword_Text, strPassword, intArgIter, FALSE) Then
  545.                 intParseCmdLine = CONST_ERROR
  546.                 Exit Function
  547.             End If
  548.  
  549.             blnPassword  =True
  550.             intArgIter = intArgIter + 1
  551.  
  552.             Case LCase(OPTION_FORMAT)
  553.  
  554.                                'If more than  1 time(s) is spcecified
  555.            If  blnFormat  =True   Then
  556.                 component.vbPrintf InvalidSyntaxMoreNoRepeatedErrorMessage, Array(Wscript.arguments.Item(intArgIter), Ucase(Wscript.ScriptName))
  557.                 intParseCmdLine = EXIT_INVALID_PARAM_DEFAULT_OPTION_REPEATED
  558.                 Exit Function
  559.             End If
  560.  
  561.             If Not component.getArguments(L_Format_Text,strFormat, intArgIter, FALSE) Then
  562.                 intParseCmdLine = CONST_ERROR
  563.                 Exit Function
  564.             End If
  565.  
  566.            
  567.             blnFormat  =True
  568.             intArgIter = intArgIter + 1
  569.            
  570.             Case LCase(OPTION_RANGE)
  571.  
  572.                    'If more than  1 time(s) is spcecified
  573.            If  blnRange  =True   Then
  574.                  component.vbPrintf InvalidSyntaxMoreNoRepeatedErrorMessage, Array(Wscript.arguments.Item(intArgIter), Ucase(Wscript.ScriptName))
  575.                 intParseCmdLine = EXIT_INVALID_PARAM_DEFAULT_OPTION_REPEATED
  576.                 Exit Function
  577.              End If
  578.  
  579.             If Not component.getArguments(L_Range_Text,strRange, intArgIter,TRUE) Then
  580.                 intParseCmdLine = CONST_ERROR
  581.                 Exit Function
  582.             End If
  583.  
  584.                 blnRange  =True
  585.                 intArgIter = intArgIter + 1
  586.  
  587.             Case LCase(OPTION_NOHEADER)
  588.  
  589.                   'If more than  1 time(s) is spcecified
  590.               If  blnNoHeader  =True   Then
  591.                  component.vbPrintf InvalidSyntaxMoreNoRepeatedErrorMessage, Array(Wscript.arguments.Item(intArgIter), Ucase(Wscript.ScriptName))
  592.                 intParseCmdLine = EXIT_INVALID_PARAM_DEFAULT_OPTION_REPEATED
  593.                 Exit Function
  594.                End If
  595.  
  596.                 blnNoHeader   = TRUE
  597.                        intArgIter = intArgIter + 1
  598.    
  599.             Case LCase(OPTION_VERBOSE)
  600.  
  601.                     'If more than  1 time(s) is spcecified
  602.             If  blnVerboseDisplay  =True   Then
  603.                 component.vbPrintf InvalidSyntaxMoreNoRepeatedErrorMessage, Array(Wscript.arguments.Item(intArgIter), Ucase(Wscript.ScriptName))
  604.                 intParseCmdLine = EXIT_INVALID_PARAM_DEFAULT_OPTION_REPEATED
  605.                 Exit Function
  606.              End If
  607.  
  608.                  blnVerboseDisplay = TRUE
  609.                  intArgIter = intArgIter + 1
  610.  
  611.             Case LCase(OPTION_FILTER)
  612.  
  613.             If Not component.getArguments(L_Filter_Text, strTemp, intArgIter, FALSE) Then
  614.                 intParseCmdLine = CONST_ERROR
  615.                 Exit Function
  616.             End If
  617.  
  618.                 arrFilters(intFilterCount) = strTemp
  619.                 intFilterCount = intFilterCount + 1
  620.                 intArgIter = intArgIter + 1
  621.  
  622.                 If ((intFilterCount MOD 5) = 0) Then
  623.                     ReDim PRESERVE arrFilters(intFilterCount + 5)
  624.                 End If
  625.  
  626.             Case LCase(OPTION_HELP)
  627.  
  628.             If  blnHelp  =True   then
  629.                     intParseCmdLine = EXIT_INVALID_PARAM
  630.                     Exit Function
  631.                 End If
  632.  
  633.             blnHelp  =True
  634.             intParseCmdLine = CONST_SHOW_USAGE
  635.             intArgIter = intArgIter + 1
  636.  
  637.             Case LCase(OPTION_LOGNAME)
  638.             If Not component.getArguments(L_Log_Text, strTemp, intArgIter, FALSE) Then
  639.                 intParseCmdLine = CONST_ERROR
  640.                 Exit Function
  641.             Else
  642.                 If NOT objLogs.Exists(LCase(strTemp)) Then
  643.                     objLogs.Add LCase(strTemp), -1
  644.                 End If
  645.                     intArgIter = intArgIter + 1
  646.             End if
  647.  
  648.             Case Else
  649.                     ' invalid   switch specified
  650.                    component.vbPrintf InvalidParameterErrorMessage, Array(Wscript.arguments.Item(intArgIter),Ucase(Wscript.ScriptName))
  651.                     Wscript.Quit(EXIT_INVALID_INPUT)
  652.          
  653.             End Select
  654. Else      
  655.                 ' invalid argument  specified  
  656.        component.vbPrintf InvalidParameterErrorMessage, Array(Wscript.arguments.Item(intArgIter),Ucase(Wscript.ScriptName))
  657.         Wscript.Quit(EXIT_INVALID_INPUT)
  658. End  IF        
  659.  
  660. Loop '** intArgIter <= Wscript.arguments.Count - 1
  661.    
  662.     ' preserving the array with current dimension
  663.    ReDim PRESERVE arrFilters(intFilterCount-1)
  664.  
  665.     ' if no logs specified for query
  666.    If (ObjLogs.Count = 0 ) Then
  667.           ObjLogs.Add "*", -1
  668.     End If  
  669.    
  670.     ' check for invalid usage of help  
  671.    If  blnHelp and  intArgIter > 1     Then    
  672.         intParseCmdLine = CONST_ERROR_USAGE
  673.         Exit Function
  674.     End If
  675.  
  676.     'check  with default case : no  arguments specified
  677.    If IsEmpty(intParseCmdLine) Then
  678.         intParseCmdLine = CONST_PROCEED
  679.     End If
  680.  
  681. End Function
  682.  
  683. '********************************************************************
  684. '* Function: ValidateArguments
  685. '*
  686. '* Purpose:  Validates the command line arguments given by the user
  687. '*
  688. '* Input:
  689. '*  [in]    strMachine         machine to query events from
  690. '*  [in]    strUserName        user name to connect to the machine
  691. '*  [in]    strPassword        password for the user
  692. '*  [in]    strFormat          the display format
  693. '*  [in]    strRange           the range of records required
  694. '*  [in]    blnNoHeader    flag to verify if noheader display is needed  
  695. '*  [out]   arrFilters         the array containing the filters
  696. '*
  697. '* Output:   Returns true if all valid else displays error message and quits
  698. '*           Gets the password from the user if not specified along with User.
  699. '*
  700. '********************************************************************
  701. Private Function ValidateArguments (ByVal strMachine, _
  702.                                     ByVal strUserName, _
  703.                                     ByVal strPassword, _
  704.                                     ByRef arrFilters, _
  705.                                     ByVal strFormat, _
  706.                                     ByVal strRange,_
  707.                                     ByVal blnNoHeader)
  708.  
  709.     ON ERROR RESUME NEXT
  710.     Err.Clear
  711.  
  712.       Dim arrTemp                     ' to store temporary array values
  713.  
  714.      ' Check if invalid Server name is given  
  715.    If   NOT  ISEMPTY(strMachine)  THEN
  716.             If Trim(strMachine) =  vbNullString  Then
  717.                 WScript.Echo (L_InValidServerName_ErrorMessage)
  718.                 WScript.Quit(EXIT_INVALID_INPUT)
  719.             End If
  720.     End If
  721.  
  722.     'Check if invalid User name is given
  723.     If   NOT  ISEMPTY(strUserName)  THEN
  724.              If Trim(strUserName) =  vbNullString  Then
  725.                 WScript.Echo (L_InValidUserName_ErrorMessage )
  726.                 WScript.Quit(EXIT_INVALID_INPUT)
  727.             End If
  728.      End If
  729.  
  730.     ' ERROR if user is given without machine OR
  731.    '          password is given without user
  732.        If ((strUserName <> VBEmpty) AND (strMachine = VBEmpty)) Then
  733.              component.vbPrintf InvalidCredentialsForServerErrorMessage, Array(Ucase(Wscript.ScriptName))
  734.             WScript.Quit(EXIT_INVALID_INPUT)
  735.         ElseIf  ((strPassword <> VBEmpty) AND (strUserName = VBEmpty))Then
  736.             component.vbPrintf InvalidCredentialsForUserErrorMessage, Array(Ucase(Wscript.ScriptName))
  737.             WScript.Quit(EXIT_INVALID_INPUT)
  738.         End If
  739.  
  740.     ' only table, list and csv display formats allowed
  741.    ' PATTERNFORMAT   '"^(table|list|csv)$"
  742.    
  743.     If CInt(component.matchPattern(PATTERNFORMAT,strFormat)) = CONST_NO_MATCHES_FOUND Then
  744.         component.vbPrintf InvalidFormatErrormessage, Array(strFormat ,Ucase(Wscript.ScriptName))
  745.         WScript.Quit(EXIT_INVALID_INPUT)
  746.     End If
  747.  
  748.       '  check : -n  header is specified  for  format of  'LIST' option  
  749.    If   blnNoHeader =True  and    Lcase(strFormat) =  Lcase(L_Const_List_Format_Text) then
  750.         WScript.Echo (L_NoHeaderaNotApplicable_ErrorMessage)
  751.         WScript.Quit(EXIT_INVALID_INPUT)
  752.         End If
  753.  
  754.     If Len(Trim(strRange)) > 0 Then
  755.         ' range is specified, valid formats are N, -N or N1-N2
  756.        ' PATTERN_RANGE    '"^(\d+|\-\d+|\d+\-\d+)$"
  757.        If CInt(component.matchPattern(PATTERN_RANGE, strRange)) = CONST_NO_MATCHES_FOUND Then
  758.             component.vbPrintf L_InvalidRange_ErrorMessage, Array(strRange)
  759.             WScript.Quit(EXIT_INVALID_INPUT)
  760.         Else
  761.  
  762.             strRange = CLng(Abs(strRange))
  763.  
  764.                     'this err an be trappped when N1-N2 option is given    
  765.            If Err.Number Then
  766.                 arrTemp =   split(strRange, "-", 2, VBBinaryCompare)
  767.                 If CLng(arrTemp(0)) => CLng(arrTemp(1)) Then
  768.                     ' invalid range
  769.                    component.vbPrintf L_InvalidRange_ErrorMessage, Array(strRange)
  770.                     WScript.Quit(EXIT_INVALID_INPUT)
  771.                 End If
  772.                     Err.Clear 'if no invalid range  N1-N2  clear the error
  773.            Else
  774.                 If Abs(strRange) = 0 Then
  775.                     component.vbPrintf L_InvalidRange_ErrorMessage, Array(strRange)
  776.                     WScript.Quit(EXIT_INVALID_INPUT)
  777.                 End If
  778.             End If
  779.         End If
  780.     End If
  781.  
  782.     ValidateArguments = TRUE
  783. End Function
  784.  
  785. '********************************************************************
  786. '* Function: ValidateFilters
  787. '*
  788. '* Purpose:  Validates the filters given by the user.
  789. '*
  790. '* Input:    [in]  Objservice     the service object
  791. '* Input:    [out] arrFilters     the array containing the filters
  792. '*
  793. '* Output:   If filter is invalid, displays error message and quits
  794. '*           If valid, filter is prepared for the query and returns true
  795. '*
  796. '********************************************************************
  797. Private Function ValidateFilters(ByRef arrFilters ,ByVal ObjService)
  798.  
  799.     ON ERROR RESUME NEXT
  800.     Err.Clear
  801.  
  802.     Dim  j                  ' to use in the loop
  803.    Dim strFilter          ' to store the user given filter (Eg:"Type eq Error")
  804.    Dim arrTempProp        ' to store the temporary array filterproperty
  805.    Dim arrTempOperAndVal  ' to store the temporary array filteroperator and filtervalue
  806.    Dim strTemp            ' to store temporary values
  807.    Dim arrTemp            ' to store temporary values of datetime when Range is given (Date1-Date2)
  808.    Dim strFilterProperty  ' the filter criteria that is specified (Eg:Type, ID)
  809.    Dim strFilterOperation ' the operation specified (Eg: eq, gt)
  810.    Dim strFilterValue     ' the filter value specified
  811.  
  812.     Dim objInstance        ' to refer to the instances of the objEnumerator
  813.    Dim objEnumerator      ' to store the results of the query is executed
  814.        Dim strTempQuery       ' string to make query  
  815.    Dim strTimeZone        ' to store the TimeZone  of the Queried system
  816.    Dim strSign            ' to store "+|-" sign value of TimeZone
  817.  
  818.     ' validate each filter stored in the array
  819.    For j = 0 to UBound(arrFilters)
  820.         strFilter = arrFilters(j)
  821.        
  822.         'check eigther  "OR" is pesent inthe filter value  
  823.        'Example  :  "type  eq warning  " OR "  type eq error"    [to support ORing in Filter Switch]
  824.        'Make a flag in this case  "blnOR"  present/not  
  825.        'split it by "OR" SEND   as No. of   Array elements
  826.        Dim  blnOR                  'boolean to refer  'OR' operation is specified
  827.        Dim  strArrFilter       'string to store array of filters if  OR is specified
  828.  
  829.         blnOR=False       'Initialise to False
  830.  
  831.        
  832.       If   UBOUND(Split(LCase(strFilter),LCase(L_OperatorOR_Text)) ) > 0  Then
  833.            'setting the flag if " OR " specified in filter
  834.             blnOR =TRUE
  835.  
  836.             'split with "OR"    
  837.             strArrFilter =  Split(LCase(strFilter),LCase(L_OperatorOR_Text))
  838.        Else
  839.                 'make single dimention array   UBOUND = 0  
  840.                strArrFilter = Array(strFilter)
  841.        End If
  842.        
  843.         Dim k       '  to use in the loop
  844.        Dim  strTempFilter ' used to format Query string    
  845.  
  846.         'process  the array for validatation
  847.        'UBOUND = 0  say normal filter specified      
  848.        For k = 0 to UBound(strArrFilter)
  849.  
  850.             If   UBound(strArrFilter) > 0 then
  851.                  strFilter =strArrFilter(k)
  852.             Else
  853.                     'this is the first element  allways
  854.                  strFilter =strArrFilter(0)
  855.             End If
  856.  
  857.          ' check if 3 parameters are passed as input to filter
  858.        ' PATTERN_FILTER  "^([a-z]+)([\s]+)([a-z]+)([\s]+)(\w+)"
  859.  
  860.         strFilter = Trim( strFilter )               ' trim the value
  861.        If CInt(component.matchPattern(PATTERN_FILTER, strFilter)) <= 0 Then
  862.             component.vbPrintf L_InvalidFilterFormat_ErrorMessage, Array(strFilter)
  863.             WScript.Quit(EXIT_INVALID_INPUT)
  864.         End If
  865.  
  866.                  
  867.             ' This to  eliminate any no.of blank Char(s)  between three valid  input values
  868.            ' i.e..filter "property ---operation ----value"
  869.            ' first  SPLIT the space delimiter string into  array size of 2.
  870.            ' and get the property value
  871.            arrTempProp = split(Trim(strFilter)," ",2,VBBinaryCompare)
  872.             strFilterProperty  = arrTempProp(0)
  873.  
  874.             ' now trim it and again  SPLIT the second element of arrTempProp into an array of size 2.
  875.            ' and get the operation and value  
  876.            arrTempOperAndVal   = split(Trim(arrTempProp(1))," ",2,VBBinaryCompare)
  877.             strFilterOperation  = arrTempOperAndVal(0)
  878.             strFilterValue      = Ltrim(arrTempOperAndVal(1))
  879.            
  880.             If LCase(strFilterProperty) = LCase(L_UserFilterDateTime_Text) OR _
  881.                 LCase(strFilterProperty) = LCase(L_UserFilterId_Text) Then
  882.                 ' the following are valid operators
  883.                If LCase(strFilterOperation) = LCase(L_OperatorEq_Text)  OR _
  884.                     LCase(strFilterOperation) = LCase(L_OperatorNe_Text) OR _
  885.                     LCase(strFilterOperation) = LCase(L_OperatorGe_Text) OR _
  886.                     LCase(strFilterOperation) = LCase(L_OperatorLe_Text) OR _
  887.                     LCase(strFilterOperation) = LCase(L_OperatorGt_Text) OR _
  888.                     LCase(strFilterOperation) = LCase(L_OperatorLt_Text) Then
  889.                    
  890.                     strTemp = ReplaceOperators(strFilterOperation)
  891.                     strFilterOperation = strTemp
  892.                 Else
  893.                     component.vbPrintf L_InvalidFilterOperation_ErrorMessage, Array(strFilterOperation, strFilter)
  894.                     WScript.Quit(EXIT_INVALID_INPUT)
  895.                 End If
  896.                
  897.             ElseIf LCase(strFilterProperty) = LCase(L_UserFilterType_Text) OR _
  898.                     LCase(strFilterProperty) = LCase(L_UserFilterUser_Text) OR _
  899.                      LCase(strFilterProperty) = LCase(L_UserFilterComputer_Text) OR _
  900.                     LCase(strFilterProperty) = LCase(L_UserFilterSource_Text) OR _
  901.                     LCase(strFilterProperty) = LCase(L_UserFilterDateCategory_Text) Then
  902.                 ' for others, only these two operators are valid
  903.                If LCase(strFilterOperation) = LCase(L_OperatorEq_Text) OR _
  904.                     LCase(strFilterOperation) = LCase(L_OperatorNe_Text) Then
  905.                    
  906.                     strTemp = ReplaceOperators(strFilterOperation)
  907.                     strFilterOperation = strTemp
  908.                 Else
  909.                     component.vbPrintf L_InvalidFilterOperation_ErrorMessage, _
  910.                             Array(strFilterOperation, strFilter)
  911.                         WScript.Quit(EXIT_INVALID_INPUT)
  912.                 End If
  913.             Else
  914.                     component.vbPrintf L_InvalidFilterOperation_ErrorMessage, _
  915.                     Array(strFilterProperty, strFilter)
  916.                     WScript.Quit(EXIT_INVALID_INPUT)
  917.             End If
  918.                
  919.             ' validate the filter asked for
  920.            Select Case LCase(strFilterProperty)
  921.            
  922.                 Case L_UserFilterDateTime_Text
  923.                
  924.                 'Checking  " OR " is only supported property  EQ "TYPE OR ID" only
  925.                If  blnOR = True then
  926.                            WScript.Echo  InvalidORSyntaxInFilterErrorMessage
  927.                            WScript.Quit(EXIT_INVALID_INPUT)
  928.                 End If
  929.  
  930.                     ' Here To find Time Zone of system from   CLASS_TIMEZONE_FILE
  931.                     strTempQuery = "SELECT *  FROM Win32_OperatingSystem "
  932.  
  933.                     Set objEnumerator = objService.ExecQuery(strTempQuery,,0)
  934.  
  935.                             ' getting the  Time Zone    
  936.                    For each objInstance in objEnumerator
  937.                              strTimeZone = objInstance.CurrentTimeZone  
  938.                     Next
  939.  
  940.                     'here to format timeZome value as '+/-' UUU
  941.  
  942.                         If Isnull(strTimeZone) or IsEmpty(strTimeZone)then
  943.                              strTimeZone =0
  944.                         End If
  945.  
  946.                         'default sign  
  947.                        strSign ="+"    
  948.                    
  949.                         IF  strTimeZone < 0  THEN
  950.                              strSign ="-"
  951.                         End If    
  952.                    
  953.                         If Len(strTimeZone) < 4 then
  954.                              If Len(strTimeZone) = 3 then
  955.                                      If strTimeZone < 0 then
  956.                                              strTimeZone = Replace(strTimeZone,"-","0")    
  957.                                      End If
  958.                              ElseIf Len(strTimeZone) = 2 then
  959.                                      If strTimeZone < 0 then
  960.                                             strTimeZone = Replace(strTimeZone,"-","00")    
  961.                                      Else
  962.                                             strTimeZone = "0" & strTimeZone    
  963.                                     End If            
  964.                              ElseIf Len(strTimeZone) = 1 then
  965.                                        IF  strTimeZone >= 0  Then
  966.                                             strTimeZone = "00" & strTimeZone    
  967.                                        End if
  968.                               End If  
  969.                                          'return to a format  as  "+|-" & UUU
  970.                             strTimeZone= strSign & strTimeZone          
  971.                          End If
  972.  
  973.                     ' check for the valid format - mm/dd/yy,hh:mm:ssPM
  974.                    ' PATTERN_DATETIME
  975.                    If CInt(component.matchPattern(PATTERN_DATETIME, strFilterValue)) > 0 Then
  976.                         If component.validateDateTime(strFilterValue) Then
  977.                             ' a valid datetime filter. Prepare for query
  978.                                strFilterProperty = FLD_FILTER_DATETIME
  979.                                 strTemp = component.changeToWMIDateTime(strFilterValue,strTimeZone)
  980.                                 ' Format the input
  981.                                ' TimeGenerated > "07/25/2000 10:12:00 PM"
  982.                                strFilterValue = Chr(34) & strTemp & Chr(34)
  983.                         End If
  984.                     Else
  985.                         ' match for range of dates in the format
  986.                        ' mm/dd/yy,hh:mm:ssPM - mm/dd/yy,hh:mm:ssAM
  987.                        ' PATTERN_DATETIME_RANGE
  988.        
  989.                         If CInt(component.matchPattern(PATTERN_DATETIME_RANGE, strFilterValue)) > 0 Then
  990.                             strFilterProperty = FLD_FILTER_DATETIME
  991.                             ' Only = operation supported in this format
  992.                            If strFilterOperation <> "=" Then
  993.                                 WScript.Echo (L_InvalidOperator_ErrorMessage)
  994.                                 WScript.Quit(EXIT_INVALID_INPUT)
  995.                             End If
  996.                    
  997.                             arrTemp = split(strFilterValue,"-",2,VBBinaryCompare)
  998.  
  999.                             If component.validateDateTime(arrTemp(0)) Then
  1000.                                     ' a valid datetime filter. Prepare for query
  1001.                                    strTemp = component.changeToWMIDateTime(arrTemp(0),strTimeZone)
  1002.                                     ' Format the input
  1003.                                    ' TimeGenerated > "07/25/2000 10:12:00 PM"
  1004.                                    strFilterOperation = ">="
  1005.                                     strFilterValue = Chr(34) & strTemp & Chr(34)
  1006.  
  1007.                                     If component.validateDateTime(arrTemp(1)) Then
  1008.                                         ' a valid datetime filter. Prepare for query
  1009.                                        strTemp = component.changeToWMIDateTime(arrTemp(1),strTimeZone)
  1010.                                         ' Format the input
  1011.                                        ' TimeGenerated > "07/25/2000 10:12:00 PM"
  1012.                                        strFilterValue = strFilterValue & _
  1013.                                         " AND " & strFilterProperty & "<="& Chr(34)_
  1014.                                         & strTemp & Chr(34)
  1015.                                     End If
  1016.                                 End If
  1017.                             Else
  1018.                                 component.vbPrintf L_InvalidDateTimeFormat_ErrorMessage, Array(strFilter)
  1019.                                 WScript.Quit(EXIT_INVALID_INPUT)
  1020.                             End If
  1021.                         End If
  1022.  
  1023.                 Case L_UserFilterType_Text
  1024.                
  1025.                         ' the following values are only valid for the "Type" filter
  1026.                        ' Valid: ERROR|INFORMATION|WARNING|SUCCESSAUDIT|FAILUREAUDIT
  1027.                        ' PATTERNTYPE
  1028.  
  1029.                         If CInt(component.matchPattern(PATTERNTYPE, strFilterValue)) = _
  1030.                                                     CONST_NO_MATCHES_FOUND Then
  1031.                             component.vbPrintf L_InvalidType_ErrorMessage, Array(strFilterValue, strFilter)
  1032.                             WScript.Quit(EXIT_INVALID_INPUT)
  1033.                         Else
  1034.         '                        here i need to check WINXP or not
  1035.                                 If  ( IsWinXP ( ObjService) = TRUE ) Then
  1036.                                    
  1037.                                            ' a valid type filter. Prepare for query
  1038.                                            If LCase(strFilterValue) =LCase(PATTERNTYPE_ERROR) Then
  1039.                                                 strFilterValue  = EVENTTYPE_ERROR
  1040.                                             ElseIf LCase(strFilterValue) =LCase(PATTERNTYPE_WARNING) Then
  1041.                                                 strFilterValue  = EVENTTYPE_WARNING
  1042.                                             ElseIf LCase(strFilterValue) =LCase(PATTERNTYPE_INFORMATION) Then
  1043.                                                 strFilterValue  = EVENTTYPE_INFORMATION
  1044.                                             ElseIf LCase(strFilterValue) =LCase(PATTERNTYPE_SUCCESSAUDIT) Then
  1045.                                                 strFilterValue  = EVENTTYPE_SUCCESSAUDIT
  1046.                                             ElseIf  LCase(strFilterValue) =LCase(PATTERNTYPE_FAILUREAUDIT) Then
  1047.                                                 strFilterValue  = EVENTTYPE_FAILUREAUDIT
  1048.                                             End If
  1049.  
  1050.                                             ' a valid type filter. Prepare for query
  1051.                                            strFilterProperty = FLD_FILTER_EVENTTYPE
  1052.                                   Else
  1053.                                        ' a valid type filter. Prepare for query
  1054.                                        If LCase(strFilterValue) =LCase(PATTERNTYPE_SUCCESSAUDIT) Then
  1055.                                             strFilterValue  = FLDFILTERTYPE_SUCCESSAUDIT
  1056.                                         ElseIf  LCase(strFilterValue) =LCase(PATTERNTYPE_FAILUREAUDIT) Then
  1057.                                             strFilterValue  = FLDFILTERTYPE_FAILUREAUDIT
  1058.                                         End If
  1059.  
  1060.                                         ' a valid type filter. Prepare for query
  1061.                                        strFilterProperty = FLD_FILTER_TYPE
  1062.                                        
  1063.                                   End If
  1064.  
  1065.                         End If
  1066.  
  1067.                 Case L_UserFilterUser_Text
  1068.  
  1069.                'Checking  " OR " is only supported property  EQ "TYPE OR ID" only
  1070.                If  blnOR = True then
  1071.                            WScript.Echo  InvalidORSyntaxInFilterErrorMessage
  1072.                            WScript.Quit(EXIT_INVALID_INPUT)
  1073.                 End If
  1074.  
  1075.                         ' these are invalid characters for a user name
  1076.                        ' PATTERN_INVALID_USER
  1077.        
  1078.                         If CInt(component.matchPattern(PATTERN_INVALID_USER, strFilterValue)) > 0 Then
  1079.                             component.vbPrintf L_InvalidUser_ErrorMessage , Array(strFilterValue, strFilter)
  1080.                             WScript.Quit(EXIT_INVALID_INPUT)
  1081.                         Else
  1082.                            
  1083.                             ' a valid user filter. Prepare for query
  1084.                            If InStr(1, strFilterValue, "\", VBBinaryCompare) Then
  1085.                                 strFilterValue = Replace(strFilterValue, "\","\\")
  1086.                             End If
  1087.                            
  1088.                             If LCase(strFilterValue) =LCase(L_TextNa_Text) Then
  1089.                                 strFilterValue  = Null
  1090.                             End If      
  1091.  
  1092.                         End If
  1093.                         strFilterProperty = FLD_FILTER_USER
  1094.  
  1095.                 Case L_UserFilterComputer_Text
  1096.                             ' a valid computer filter. Prepare for query
  1097.                            strFilterProperty = FLD_FILTER_COMPUTER
  1098.  
  1099.                 'Checking  " OR " is only supported property  EQ "TYPE OR ID" only
  1100.                If  blnOR = True then
  1101.                            WScript.Echo  InvalidORSyntaxInFilterErrorMessage
  1102.                            WScript.Quit(EXIT_INVALID_INPUT)
  1103.                 End If
  1104.  
  1105.                 Case L_UserFilterSource_Text
  1106.                             ' a valid Source filter. Prepare for query
  1107.                            strFilterProperty = FLD_FILTER_SOURCE
  1108.  
  1109.                 'Checking  " OR " is only supported property  EQ "TYPE OR ID" only
  1110.                If  blnOR = True then
  1111.                            WScript.Echo  InvalidORSyntaxInFilterErrorMessage
  1112.                            WScript.Quit(EXIT_INVALID_INPUT)
  1113.                 End If
  1114.  
  1115.                 Case L_UserFilterDateCategory_Text
  1116.  
  1117.                 'Checking  " OR " is only supported property  EQ "TYPE OR ID" only
  1118.                If  blnOR = True then
  1119.                            WScript.Echo  InvalidORSyntaxInFilterErrorMessage
  1120.                            WScript.Quit(EXIT_INVALID_INPUT)
  1121.                 End If
  1122.  
  1123.                             ' a valid Category filter. Prepare for query
  1124.                            If LCase(strFilterValue) =LCase(L_TextNone_Text) Then
  1125.                                 strFilterValue  = Null
  1126.                             End If
  1127.  
  1128.                              strFilterProperty = FLD_FILTER_CATEGORY
  1129.                    
  1130.                 Case L_UserFilterId_Text
  1131.                         ' check if the given id is a number
  1132.                        ' PATTERN_ID '"^(\d+)$"
  1133.                        If CInt(component.matchPattern(PATTERN_ID, strFilterValue)) = CONST_NO_MATCHES_FOUND Then
  1134.                             component.vbPrintf L_InvalidId_ErrorMessage, Array(strFilterValue, strFilter)
  1135.                             WScript.Quit(EXIT_INVALID_INPUT)
  1136.                         Else
  1137.                             ' Invalid ID Number  validation    
  1138.                            If  ( Clng(strFilterValue)   >  CONST_ID_NUMBER )Then    
  1139.                                 component.vbPrintf L_InvalidId_ErrorMessage, Array(strFilterValue, strFilter)
  1140.                                 WScript.Quit(EXIT_INVALID_INPUT)
  1141.                             End If
  1142.  
  1143.                             ' a  valid id filter. Prepare for query
  1144.                            strFilterProperty = FLD_FILTER_ID
  1145.                         End If
  1146.  
  1147.                 Case Else
  1148.                         ' invalid filter specified
  1149.                        component.vbPrintf L_InvalidFilter_ErrorMessage, Array(strFilterProperty, strFilter)
  1150.                         WScript.Quit(EXIT_INVALID_INPUT)
  1151.             End Select
  1152.  
  1153.             If LCase(strFilterProperty) = LCase(FLD_FILTER_DATETIME) OR IsNull(strFilterValue) Then
  1154.                 ' This is to handle NULL Property  values i.e for category ,type          
  1155.                If   IsNull(strFilterValue) Then
  1156.                  strFilter = strFilterProperty & strFilterOperation & strFilterValue & "Null"
  1157.                 Else
  1158.                  strFilter = strFilterProperty & strFilterOperation & strFilterValue  
  1159.                 End If
  1160.                
  1161.             Else
  1162.                 strFilter = strFilterProperty & _
  1163.                             strFilterOperation & Chr(34) & strFilterValue & Chr(34)
  1164.             End If
  1165.  
  1166.         'Binding the string with "OR" to Prepare for query if blnOR  is true
  1167.         If blnOR =TRUE Then
  1168.  
  1169.             If k =  0 then  
  1170.                         strTempFilter = strFilter
  1171.             Else
  1172.                         strTempFilter = strTempFilter  &  " OR " &  strFilter
  1173.             End If
  1174.        
  1175.         End If
  1176.  
  1177.     Next  
  1178.  
  1179.         'Set again making single filter string element if blnOR is TRUE
  1180.    If blnOR =TRUE Then
  1181.                 'this  "()" Add  the order of precedence of operation is SQL
  1182.                 strFilter = "( " & strTempFilter & ")"
  1183.         End If
  1184.  
  1185.     'Here setting filter to main array
  1186.         arrFilters(j) = strFilter
  1187.  
  1188.  
  1189.     Next
  1190.  
  1191.     ValidateFilters = TRUE
  1192.  
  1193. End Function
  1194.  
  1195. '********************************************************************
  1196. '* Function: ReplaceOperators
  1197. '*
  1198. '* Purpose:  Replaces the operator in string form with its symbol
  1199. '*
  1200. '* Input:  
  1201. '*       [in]    strFilterOperation     the operation
  1202. '*
  1203. '* Output:   Returns the symbolic operator
  1204. '*           If invalid operator, displays error message and quits
  1205. '*
  1206. '********************************************************************
  1207. Private Function ReplaceOperators(ByVal strFilterOperation)
  1208.     ON ERROR RESUME NEXT
  1209.     Err.Clear
  1210.  
  1211.     Select Case LCase(strFilterOperation)
  1212.  
  1213.         Case L_OperatorEq_Text
  1214.                     ReplaceOperators = SYMBOL_OPERATOR_EQ
  1215.  
  1216.         Case L_OperatorNe_Text
  1217.                     ReplaceOperators = SYMBOL_OPERATOR_NE
  1218.  
  1219.         Case L_OperatorGe_Text
  1220.                     ReplaceOperators = SYMBOL_OPERATOR_GE
  1221.  
  1222.         Case L_OperatorLe_Text
  1223.                     ReplaceOperators = SYMBOL_OPERATOR_LE
  1224.  
  1225.         Case L_OperatorGt_Text
  1226.                     ReplaceOperators = SYMBOL_OPERATOR_GT
  1227.  
  1228.         Case L_OperatorLt_Text
  1229.                     ReplaceOperators = SYMBOL_OPERATOR_LT
  1230.  
  1231.         Case Else
  1232.                 ' not a valid operator
  1233.                component.vbPrintf L_Invalid_ErrorMessage, Array(strFilterOperation)
  1234.                 WScript.Quit(EXIT_INVALID_PARAM)
  1235.     End Select
  1236. End Function
  1237. '********************************************************************
  1238. '* Sub : VerifyLogAndGetMaxRecords
  1239. '*
  1240. '* Purpose:  populates the output array  with count of records in given  input array
  1241. '*
  1242. '* Input:    [in]  objService        the service object
  1243. '*           [out] objLogs           the object containing the logs & max count of records corresponding log
  1244. '*
  1245. '* Output:   array's  are  populates with logfile names and its count of  max records
  1246. '*
  1247. '********************************************************************
  1248. Private Sub VerifyLogAndGetMaxRecords(ByVal objService, _
  1249.                  ByRef objLogs)
  1250.  
  1251.     ON ERROR RESUME NEXT
  1252.     Err.Clear
  1253.    
  1254.     Dim strTempQuery     ' string to make query  
  1255.    Dim objEnumerator    ' to get the collection object after query
  1256.    Dim objInstance      ' to refer to each instance of the results got
  1257.    Dim i                ' for  initialing  loop
  1258.    Dim strLogFile       ' used to   store log file  inside loop  
  1259.    Dim arrKeyName       ' used to store key value of Dictionary object for processing loop  
  1260.  
  1261.     arrKeyName = objLogs.Keys
  1262.  
  1263.     For i = 0  to  objLogs.Count -1
  1264.         strLogFile = arrKeyName(i)
  1265.         If Not strLogFile = "*" Then
  1266.             ' Check if log file exists, by querying
  1267.            strTempQuery = "SELECT NumberOfRecords FROM Win32_NTEventlogFile " &_
  1268.                             "WHERE LogfileName=" & Chr(34) & strLogFile & Chr(34)
  1269.  
  1270.             Set objEnumerator = objService.ExecQuery(strTempQuery,,0)
  1271.  
  1272.             If Err.Number Then
  1273.                 component.vbPrintf L_ExecuteQuery_ErrorMessage, Array(strLogFile)
  1274.                 WScript.Quit(EXIT_METHOD_FAIL)
  1275.             End If
  1276.  
  1277.             ' check if given log is present
  1278.            If ObjEnumerator.Count <> 1 Then
  1279.                 component.vbPrintf L_LogDoesNotExist_ErrorMessage, Array(strLogFile)
  1280.                 'If  Count of Logs = 1  Quit  Here
  1281.                If objLogs.Count= 1 Then
  1282.                      WScript.Quit(EXIT_INVALID_INPUT)
  1283.                End If  
  1284.                'If more proceed ..
  1285.                objLogs.Remove(strLogFile)
  1286.             Else
  1287.                 ' get maximum number of records in that log(used if range specified)
  1288.                For each objInstance in objEnumerator
  1289.                     If objInstance.NumberOfRecords <> "" Then
  1290.                         objLogs.Item(strLogFile) = objInstance.NumberOfRecords
  1291.                     Else
  1292.                         objLogs.Item(strLogFile) = 0
  1293.                     End If
  1294.                 Next
  1295.             End If
  1296.             Set ObjEnumerator = Nothing
  1297.         End If
  1298.     Next
  1299.  
  1300.     If objLogs.Exists("*") Then
  1301.         ' if the * is specified, populate array  with elements
  1302.        objLogs.Remove("*")
  1303.         ' get the instances of the logs present in the system
  1304.        Set objEnumerator = objService.InstancesOf(CLASS_EVENTLOG_FILE)
  1305.        
  1306.          If Err.number  Then
  1307.             Wscript.Echo (L_InstancesFailed_ErrorMessage)
  1308.             WScript.Quit(EXIT_METHOD_FAIL)
  1309.          End If  
  1310.    
  1311.         ' if no logs present
  1312.        If objEnumerator.Count <= 0 Then
  1313.             WScript.Echo (L_InfoNoLogsPresent_Message)
  1314.             WScript.Quit(EXIT_UNEXPECTED)
  1315.         Else
  1316.             For Each objInstance In objEnumerator
  1317.                 If Not IsEmpty(objInstance.LogfileName) Then
  1318.                             If NOT objLogs.Exists(LCase(objInstance.LogfileName)) Then
  1319.                                 If objInstance.NumberOfRecords Then
  1320.                                     objLogs.Add LCase(objInstance.LogfileName), objInstance.NumberOfRecords
  1321.                                 Else
  1322.                                     objLogs.Add LCase(objInstance.LogfileName), 0
  1323.                                 End If
  1324.                             End If
  1325.                 End If
  1326.             Next
  1327.         End If
  1328.     End If
  1329.  
  1330. End Sub
  1331.  
  1332. '********************************************************************
  1333. '* Function: BuildFiltersForQuery
  1334. '*
  1335. '* Purpose:  Builds the query with the filter arguments
  1336. '*
  1337. '* Input:    [in] arrFilters    the array containing the filter conditions
  1338. '*
  1339. '* Output:   Returns the string to be concatenated to the main query
  1340. '*
  1341. '********************************************************************
  1342. Function BuildFiltersForQuery(ByVal arrFilters)
  1343.     ON ERROR RESUME NEXT
  1344.     Err.Clear
  1345.  
  1346.     Dim strTempFilter    ' to store the return string
  1347.    Dim i                ' used in loop
  1348.  
  1349.     strTempFilter = ""
  1350.     For i = 0 to UBound(arrFilters)
  1351.             strTempFilter = strTempFilter & " AND "
  1352.             strTempFilter = strTempFilter & arrFilters(i)
  1353.     Next
  1354.      
  1355.     BuildFiltersForQuery = strTempFilter
  1356.  
  1357. End Function
  1358.  
  1359. '********************************************************************
  1360. '* Function : BuildRangeForQuery
  1361. '*
  1362. '* Purpose:  Builds the range boundaries to display the records.
  1363. '*
  1364. '* Input:   [in] strRange             ' the range specified by the user
  1365. '*                                      Will be in the format N, -N or N-N
  1366. '*          [in]  intFiltersSpecified ' array containing the filters number
  1367. '*          [in]  objService          ' the service object
  1368. '*          [out] intRecordRangeFrom  ' where do we start the display of records?
  1369. '*          [out] intRecordRangeTo    ' where do we stop displaying records
  1370. '*          [out] strFilterLog        ' log file to build query
  1371. '*          [out] strQuery            ' to build query according to given  Range Type
  1372. '* Output:   Sets the value for the start and end of display boundaries.
  1373. '*
  1374. '********************************************************************
  1375. Private Function BuildRangeForQuery(ByVal strRange, _
  1376.                                ByRef intRecordRangeFrom, _
  1377.                                ByRef intRecordRangeTo,_
  1378.                                ByVal intFiltersSpecified,_
  1379.                                ByRef strQuery,_
  1380.                                ByVal ObjService,_
  1381.                                ByVal strFilterLog )
  1382.  
  1383.     ON ERROR RESUME NEXT
  1384.     Err.Clear
  1385.  
  1386.     Dim intMaxEventRecordsPresent   ' to store the max recods in the log
  1387.    Dim arrRangeValues              ' to store the split values if range is of the type N-N
  1388.    Dim objInstance                 ' to refer to the instances of the objEnumerator
  1389.    Dim objEnumerator               ' to store the results of the query is executed
  1390.    Dim FilterRecordCount           ' to store the count of records if filter with +N  specified    
  1391.    
  1392.     FilterRecordCount  = 0        
  1393.  
  1394.         BuildRangeForQuery  = strquery    'intialize  
  1395.  
  1396.     Dim currentMaxRecordnumber  'curentMaxrecord number  
  1397.    Dim currentMinRecordnumber  'curentMinrecord number  
  1398.  
  1399.     currentMaxRecordnumber = 0
  1400.     currentMinRecordnumber = 0
  1401.    
  1402.     ' save the max. no. of records available in the current log
  1403.    intMaxEventRecordsPresent = intRecordRangeTo
  1404.  
  1405.  
  1406.            ' find  the count of events / logfile   if Filter is  specified .
  1407.        If intFiltersSpecified >= 0 Then
  1408.                     Set objEnumerator = objService.ExecQuery(strQuery,"WQL",0,null)
  1409.                                 If Err.number Then      
  1410.                                     component.vbPrintf L_ExecuteQuery_ErrorMessage, Array(strFilterLog)
  1411.                                     Exit Function
  1412.                                 End if  
  1413.                                
  1414.                                 FilterRecordCount= objEnumerator.count
  1415.                
  1416.                     Set objEnumerator= Nothing  'releases the memory
  1417.        End If  
  1418.    
  1419.     ' check the type of range specified ( first N / last N /    N1 - N2 )
  1420.    If ( IsNumeric(strRange) ) Then
  1421.  
  1422.         ' range is first N or last N
  1423.        ' now check whether it is first N or last N
  1424.        If strRange < 0  Then
  1425.                             If intFiltersSpecified >= 0 Then
  1426.                                         ' first  N  records  
  1427.                                        ' initial the counter so that all the out is displayed
  1428.                            
  1429.                                             If   FilterRecordCount   >  CLng(Abs(strRange))  then
  1430.                                                     intRecordRangeFrom = FilterRecordCount    -  CLng(Abs(strRange)) + 1
  1431.                                                     intRecordRangeTo   = FilterRecordCount  
  1432.                                              Else
  1433.                                                     intRecordRangeFrom = 0
  1434.                                                     intRecordRangeTo   = FilterRecordCount  
  1435.                                             End If
  1436.  
  1437.                                 Else        
  1438.  
  1439.                                             Set objEnumerator = objService.ExecQuery(strQuery,"WQL",48,null)
  1440.                                                     For Each objInstance  In  objEnumerator
  1441.                                                               currentMaxRecordnumber= objInstance.RecordNumber
  1442.                                                           Exit for
  1443.                                                     Next
  1444.                                        
  1445.                                             If  currentMaxRecordnumber >   intMaxEventRecordsPresent then
  1446.                                                          currentMinRecordnumber  = currentMaxRecordnumber - intMaxEventRecordsPresent
  1447.                                                         intMaxEventRecordsPresent =  currentMaxRecordnumber        
  1448.                                             End If  
  1449.                                                 Set objEnumerator= Nothing  'releases the memory
  1450.  
  1451.                                             ' N  means  record number <= N  
  1452.                                            ' initial the counter s+o that all the out is displayed
  1453.                                            ' build the query
  1454.                                             BuildRangeForQuery = strQuery & " AND RecordNumber <= "&   CLng(Abs(strRange))  + currentMinRecordnumber
  1455.                                            
  1456.                                End If
  1457.                     Else
  1458.                                 ' *** range is last N (i.e -N)
  1459.                                If intFiltersSpecified >= 0 Then
  1460.  
  1461.                                         If   FilterRecordCount   >  CLng(Abs(strRange))  then
  1462.                                             intRecordRangeFrom =0
  1463.                                             intRecordRangeTo   =   CLng(Abs(strRange))  
  1464.                                         Else
  1465.                                             intRecordRangeFrom =0
  1466.                                             intRecordRangeTo   =   FilterRecordCount  
  1467.                                         End If
  1468.  
  1469.                                 Else
  1470.  
  1471.                                         Set objEnumerator = objService.ExecQuery(strQuery,"WQL",48,null)
  1472.                                                 'getting current max recordnumber  
  1473.                                                For Each objInstance  In  objEnumerator
  1474.                                                           currentMaxRecordnumber= objInstance.RecordNumber
  1475.                                                       Exit for
  1476.                                                 Next
  1477.  
  1478.                                         If  currentMaxRecordnumber >   intMaxEventRecordsPresent then
  1479.                                                      currentMinRecordnumber  = currentMaxRecordnumber - intMaxEventRecordsPresent
  1480.                                                     intMaxEventRecordsPresent =  currentMaxRecordnumber        
  1481.                                         End If          
  1482.  
  1483.                                                 Set objEnumerator= Nothing  'releases the memory
  1484.  
  1485.                                     ' -N  means  record number > (maxNumber - N )
  1486.                                    ' initial the counter so that all the out is displayed
  1487.                                    ' build the query
  1488.                                    If  CLng(Abs(strRange)) >  intMaxEventRecordsPresent Then
  1489.                                         'Show all records  
  1490.                                          BuildRangeForQuery =strQuery &  " AND RecordNumber > 0 "  
  1491.                                     Else
  1492.                                             BuildRangeForQuery =strQuery &  " AND RecordNumber > " & intMaxEventRecordsPresent - CLng(Abs(strRange))
  1493.                                     End If
  1494.                                 End If
  1495.                     End If
  1496.     Else
  1497.         ' range of records asked for N-N case
  1498.         arrRangeValues = split(strRange,"-", 2, VBBinaryCompare)  
  1499.  
  1500.         If intFiltersSpecified >= 0 Then
  1501.                 If  CLng(arrRangeValues(0)) <   FilterRecordCount then
  1502.                
  1503.                      ' initial the counter so that all the out is displayed
  1504.                        intRecordRangeFrom = CLng(arrRangeValues(0))  
  1505.                         intRecordRangeTo    = CLng(arrRangeValues(1))
  1506.                 Else
  1507.                           'forcebly  putting the invaid query
  1508.                           'when  N1 >  FilterRecordCount to avoid unnessaray   looping between  intRecordRangeFrom TO  intRecordRangeTo
  1509.                             BuildRangeForQuery =strQuery &  " AND RecordNumber = 0 "
  1510.                 End If  
  1511.         Else            
  1512.                 Set objEnumerator = objService.ExecQuery(strQuery,"WQL",48,null)
  1513.                             For Each objInstance  In  objEnumerator
  1514.                                       currentMaxRecordnumber= objInstance.RecordNumber
  1515.                                   Exit for
  1516.                             Next
  1517.  
  1518.                     If  currentMaxRecordnumber >   intMaxEventRecordsPresent then
  1519.                                  currentMinRecordnumber  = currentMaxRecordnumber - intMaxEventRecordsPresent
  1520.                                 intMaxEventRecordsPresent =  currentMaxRecordnumber        
  1521.                     End If
  1522.                 Set objEnumerator= Nothing  'releases the memory
  1523.  
  1524.             ' build the query
  1525.            BuildRangeForQuery =strQuery &  " AND RecordNumber >= "&  CLng(arrRangeValues(0))+ currentMinRecordnumber &  " AND RecordNumber <= " &   CLng(arrRangeValues(1)) + currentMinRecordnumber
  1526.  
  1527.         End If
  1528.     End If
  1529.  
  1530. End Function
  1531.  
  1532. '********************************************************************
  1533. '* Sub:     ShowEvents
  1534. '*
  1535. '* Purpose: Displays the EventLog details
  1536. '*
  1537. '* Input:  
  1538. '*  [in]    strMachine          machine to query events from
  1539. '*  [in]    strUserName         user name to connect to the machine
  1540. '*  [in]    strPassword         password for the user
  1541. '*  [in]    arrFilters          the array containing the filters
  1542. '*  [in]    strFormat           the display format
  1543. '*  [in]    strRange            the range of records required
  1544. '*  [in]    blnVerboseDisplay  flag to verify if verbose display is needed
  1545. '*  [in]    blnNoHeader        flag to verify if noheader display is needed  
  1546. '*  [in]    objLogs             to store all the given logfles
  1547. '* Output:  Displays error message and quits if connection fails
  1548. '*          Calls component.showResults() to display the event records
  1549. '*
  1550. '********************************************************************
  1551. Private Sub ShowEvents(ByVal strMachine, _
  1552.                        ByVal strUserName, _
  1553.                        ByVal strPassword, _
  1554.                        ByRef arrFilters, _
  1555.                        ByVal strFormat, _
  1556.                        ByVal strRange, _
  1557.                        ByVal blnVerboseDisplay, _
  1558.                        ByVal blnNoHeader,_
  1559.                        ByRef objLogs)
  1560.  
  1561.     ON ERROR RESUME NEXT
  1562.     Err.Clear
  1563.  
  1564.     Dim objService         ' the service object
  1565.    Dim objEnumerator      ' to store the results of the query is executed
  1566.    Dim objInstance        ' to refer to the instances of the objEnumerator
  1567.    Dim strFilterLog       ' to refer to each log specified by the user
  1568.    Dim strTemp            ' to store the temporary variables
  1569.    Dim strQuery           ' to store the query obtained for given conditions
  1570.    Dim arrResults         ' to store the columns of each filter
  1571.    Dim arrHeader          ' to store the array header values
  1572.    Dim arrMaxLength       ' to store the maximum length for each column
  1573.    Dim arrFinalResults    ' used to send the arrResults to component.showResults()
  1574.    Dim arrTemp            ' to store temporary array values
  1575.    Dim intLoopCount       ' used in the loop
  1576.    Dim intElementCount    ' used as array subscript
  1577.    Dim strFilterQuery     ' to store the query for the given filters
  1578.    Dim intResultCount     ' used to  count no of records that are fetched  in the query        
  1579.    Dim blnPrintHeader     ' used to  check header is printed or not in resulted Query
  1580.    
  1581.     ' the following are used for implementing the range option
  1582.    Dim intRecordRangeFrom    ' to store the display record beginning number
  1583.    Dim intRecordRangeTo      ' to store the display record ending number
  1584.    Dim arrKeyName            ' to  store then key value of  dictionary   object
  1585.    Dim strTempQuery          ' to store a string for -N range values
  1586.    Dim arrblnDisplay         ' array to show the  status of display of verbose mode  for showresults function
  1587.    Dim intDataCount       ' used in looping to  get value of  Insertion string   for the field "Description column"
  1588.    Dim i                           'used for looping to enable All special privileges
  1589.  
  1590.    ' flag to set condition specific locale  & default value setting
  1591.    Dim  bLocaleChanged
  1592.     bLocaleChanged =FALSE
  1593.  
  1594.     'Validating  the arguments   which is passed from commandline    
  1595.    If NOT (ValidateArguments(strMachine, strUserName, strPassword, _
  1596.             arrFilters, strFormat, strRange , blnNoHeader)) Then
  1597.            WScript.Quit(EXIT_UNEXPECTED)
  1598.     End If
  1599.  
  1600.  
  1601.   ' checking for UNC  format  for the system  name
  1602.   If  Left(strMachine,2) =  UNC_Format_Servername  Then
  1603.             If Len(strMachine) = 2  Then    
  1604.                  component.vbPrintf InvalidInputErrorMessage ,Array(Wscript.ScriptName)
  1605.                  WScript.Quit(EXIT_UNEXPECTED)
  1606.           End if
  1607.            strMachine = Mid(strMachine,3,Len(strMachine))
  1608.    End If
  1609.  
  1610.   'getting the password ....
  1611.    If ((strUserName <> VBEmpty) AND (strPassword = VBEmpty)) Then
  1612.              strPassword = component.getPassword()
  1613.     End If
  1614.  
  1615.  ' To set  GetSupportedUserLocale for Some  Diff locales
  1616.    bLocaleChanged =GetSupportedUserLocale()
  1617.  
  1618.     'Establish a connection with the server.
  1619.    If NOT component.wmiConnect(CONST_NAMESPACE_CIMV2 , _
  1620.                       strUserName , _
  1621.                       strPassword , _
  1622.                       strMachine  , _
  1623.                       blnLocalConnection , _
  1624.                       objService  ) Then
  1625.  
  1626.             Wscript.Echo(L_HintCheckConnection_Message)        
  1627.             WScript.Quit(EXIT_METHOD_FAIL)
  1628.        
  1629.     End If
  1630.  
  1631.     ' set the previlige's  To query  all event's in eventlog's .
  1632.    objService.Security_.Privileges.AddAsString("SeSecurityPrivilege")
  1633.  
  1634.     'Enable all privileges as some DC's were requiring special privileges
  1635.    For i = 1 to 26
  1636.         objService.Security_.Privileges.Add(i)
  1637.     Next
  1638.  
  1639.     ' get the HostName from the function
  1640.    strMachine = component.getHostName( objService)
  1641.  
  1642.     ' Validating  the Filters  which is passed from commandline    
  1643.    If UBound(arrFilters) >= 0 Then
  1644.         ' filters are specified. Validate them
  1645.        If Not  ValidateFilters(arrFilters,objService ) Then
  1646.             WScript.Quit(EXIT_INVALID_INPUT)
  1647.         End If
  1648.     End If
  1649.    
  1650.  
  1651.     blnPrintHeader = TRUE
  1652.  
  1653.     If blnNoHeader Then
  1654.         blnPrintHeader = FALSE
  1655.     End If
  1656.  
  1657.     ' Initialize - header to display, the maximum length of each column and
  1658.    '              number of columns present
  1659.    arrHeader = Array(L_ColHeaderType_Text,L_ColHeaderEventcode_Text, L_ColHeaderDateTime_Text,_
  1660.                           L_ColHeaderSource_Text,L_ColHeaderComputerName_Text)
  1661.     ' first initialize the array with N/A    
  1662.    arrResults = Array(L_TextNa_Text,L_TextNa_Text,L_TextNa_Text,L_TextNa_Text,L_TextNa_Text,L_TextNa_Text,_
  1663.                             L_TextNa_Text,L_TextNa_Text)
  1664.  
  1665.     arrMaxLength = Array(13,6, 24, 17, 14, 15, 20,750)
  1666.     arrblnDisplay = Array(0, 0, 0, 0, 0, 1, 1, 1)
  1667.  
  1668.     If blnVerboseDisplay Then
  1669.         arrblnDisplay = Array(0, 0, 0, 0, 0, 0, 0,0)
  1670.         arrHeader = Array( L_ColHeaderType_Text,L_ColHeaderEventcode_Text, L_ColHeaderDateTime_Text, _
  1671.                           L_ColHeaderSource_Text,L_ColHeaderComputerName_Text,L_ColHeaderCategory_Text,_
  1672.                           L_ColHeaderUser_Text, L_ColHeaderDesription_Text)
  1673.     End IF
  1674.  
  1675.         If UBound(arrFilters) >=0 Then
  1676.         strFilterQuery = BuildFiltersForQuery(arrFilters)
  1677.     End If
  1678.    
  1679.     ' call function to verify given log and also get records count in log
  1680.    Call VerifyLogAndGetMaxRecords(objService, objLogs)
  1681.  
  1682.     arrKeyName = objLogs.Keys
  1683.  
  1684.     intResultCount = 0
  1685.     intLoopCount = 0
  1686.  
  1687.       'blank line before first data is  displayed on console
  1688.        WScript.Echo EmptyLine_Text
  1689.  
  1690.     Do While (intLoopCount < objLogs.Count)
  1691.  
  1692.         'setting Header to print every Log file  explicilty
  1693.        If blnNoHeader Then
  1694.             blnPrintHeader = FALSE
  1695.         Else
  1696.                 blnPrintHeader = TRUE
  1697.         End If
  1698.        
  1699.  
  1700.         If CInt(objLogs.Item(arrKeyName(intLoopCount))) > 0 Then        
  1701.             strFilterLog = arrKeyName(intLoopCount)
  1702.             intRecordRangeFrom = 0
  1703.             intRecordRangeTo = CInt(objLogs.Item(arrKeyName(intLoopCount)))
  1704.            
  1705.            
  1706.             ' build the query
  1707.            strQuery = "Select * FROM Win32_NTLogEvent WHERE Logfile=" &_
  1708.                                 Chr(34) & strFilterLog & Chr(34)
  1709.  
  1710.             If UBound(arrFilters) >=0  Then
  1711.                 strQuery = strQuery & strFilterQuery
  1712.             End If
  1713.  
  1714.            
  1715.             If Len(Trim(CStr(strRange))) > 0 Then
  1716.                 ' building again query  for -N  condition in range switch  
  1717.                strQuery = BuildRangeForQuery(strRange,intRecordRangeFrom, _
  1718.                           intRecordRangeTo, UBound(arrFilters),strQuery,objService,strFilterLog)
  1719.                                
  1720.             End If
  1721.  
  1722.             ' process the results, else go for next log
  1723.            Set objEnumerator = objService.ExecQuery(strQuery,"WQL",48,null)
  1724.                
  1725.             If  Err.Number Then
  1726.                 component.vbPrintf L_ExecuteQuery_ErrorMessage, Array(strFilterLog)
  1727.                 ' if error occurred in the query, go for next log
  1728.                intLoopCount = intLoopCount + 1
  1729.                 Err.clear      ' for next loop  if more logs present
  1730.            Else
  1731.  
  1732.                 intElementCount = 0
  1733.  
  1734.                 ReDim arrFinalResults(CONST_ARRAYBOUND_NUMBER)
  1735.  
  1736.                 For each objInstance in objEnumerator
  1737.  
  1738.                     ' inside error trapping for most unexpected case...  
  1739.                    If Err.number   then  Exit For      
  1740.  
  1741.                     intResultCount = intResultCount + 1
  1742.                
  1743.                         ' print the header for each log file along  with Host Name
  1744.                        'imp:: if  and  only if  have Data
  1745.                    If  intResultCount = 1 Then
  1746.                             WScript.Echo(String(78,"-"))
  1747.                             component.vbPrintf L_InfoDisplayLog_Message ,Array(strFilterLog,strMachine)
  1748.                             WScript.Echo(String(78,"-"))
  1749.                     End If
  1750.  
  1751.                     ' check whether the current record is fitting in
  1752.                    ' the required range
  1753.                    If ( intResultCount >= intRecordRangeFrom ) And _
  1754.                        ( intResultCount <= intRecordRangeTo ) Then
  1755.                        ' record fitting the range ... this has to be displayed
  1756.  
  1757.                         If objInstance.Type <> "" Then
  1758.                             arrResults(0) = objInstance.Type
  1759.                         Else
  1760.                             arrResults(0) = L_TextNa_Text
  1761.                         End If
  1762.  
  1763.                         If objInstance.EventCode <> "" Then
  1764.                             arrResults(1) = objInstance.EventCode
  1765.                         Else
  1766.                             arrResults(1) = L_TextNa_Text
  1767.                         End If
  1768.  
  1769.                         If (NOT IsEmpty(objInstance.TimeGenerated)) Then
  1770.  
  1771.                             strTemp = objInstance.TimeGenerated
  1772.                                    
  1773.                                    'is LOCALE CHANGED  
  1774.                                 If bLocaleChanged <> TRUE Then
  1775.                                       'format DatTime as DATE & "Space" & TIME    
  1776.                                       arrResults(2)= Formatdatetime( Mid(strTemp,5,2) & "/"  & Mid(strTemp,7,2) & "/"  &_
  1777.                                                Mid(strTemp,1,4)) & " " & formatdatetime( Mid(strTemp,9,2) & ":" &_
  1778.                                                Mid(strTemp,11,2) & ":" & Mid(strTemp,13,2))
  1779.                                   Else
  1780.                                      arrResults(2) = Mid(strTemp,5,2) & "/"  & Mid(strTemp,7,2) & "/"  &_
  1781.                                                Mid(strTemp,1,4) & " " & Mid(strTemp,9,2) & ":" &_
  1782.                                                Mid(strTemp,11,2) & ":" & Mid(strTemp,13,2)
  1783.                                  End  If
  1784.                
  1785.                         Else
  1786.                                 arrResults(2) = L_TextNa_Text
  1787.                         End If
  1788.  
  1789.                         If objInstance.SourceName <> "" Then
  1790.                             arrResults(3) = objInstance.SourceName
  1791.                         Else
  1792.                             arrResults(3) = L_TextNa_Text
  1793.                         End If
  1794.  
  1795.                         If objInstance.ComputerName <> "" Then
  1796.                                 arrResults(4) =objInstance.ComputerName
  1797.                             Else
  1798.                                 arrResults(4) = L_TextNa_Text
  1799.                             End If
  1800.                        
  1801.                     If blnVerboseDisplay Then
  1802.                             If objInstance.CategoryString <> "" Then
  1803.                                 arrResults(5) = Replace(objInstance.CategoryString, VbCrLf, "")
  1804.                             Else
  1805.                                 arrResults(5) = L_TextNone_Text   ' None display
  1806.                            End If
  1807.  
  1808.                             If (NOT IsNull(objInstance.User)) Then
  1809.                                 arrResults(6) = objInstance.User
  1810.                             Else
  1811.                                 arrResults(6) = L_TextNa_Text
  1812.                             End If
  1813.  
  1814.                             If objInstance.Message <> "" Then
  1815.                                 arrResults(7) = Trim(Replace(objInstance.Message, VbCrLf, " "))
  1816.                             Else
  1817.                                 'Check here eighter value in presenet "InsertionStrings" column .
  1818.                                If (NOT IsNull(objInstance.InsertionStrings)) Then
  1819.                                     arrTemp = objInstance.InsertionStrings
  1820.                                     'removing default value "N/A"
  1821.                                    arrResults(7)= ""
  1822.                                     For intDataCount = 0 to UBound(arrTemp)
  1823.                                     arrResults(7) = arrResults(7) & " " & arrTemp(intDataCount)
  1824.                                     Next
  1825.  
  1826.                                     arrResults(7) = Trim(arrResults(7))
  1827.                                 Else
  1828.                                     arrResults(7) = L_TextNa_Text
  1829.                                 End If
  1830.  
  1831.                             End If
  1832.  
  1833.                     End If
  1834.                        
  1835.                         ' add the record to the queue of records that has to be displayed
  1836.                        arrFinalResults( intElementCount ) = arrResults
  1837.                         intElementCount = intElementCount + 1       ' increment the buffer
  1838.                        ' check whether the output buffer is filled and ready for display
  1839.                        ' onto the screen or not
  1840.                        If intElementCount = CONST_ARRAYBOUND_NUMBER +1  Then
  1841.                                  ' Call the display function with required parameters
  1842.                                Call  component.showResults(arrHeader, arrFinalResults, arrMaxLength, _
  1843.                                           strFormat, blnPrintHeader, arrblnDisplay)
  1844.                                 blnPrintHeader = FALSE
  1845.                                
  1846.                                 Redim arrFinalResults(CONST_ARRAYBOUND_NUMBER) ' clear the existing buffer contents
  1847.                                intElementCount = 0     ' reset the buffer start
  1848.                        End If
  1849.                     End If
  1850.  
  1851.                     ' check whether the last record number that has to be displayed is
  1852.                    ' crossed or not ... if crossed exit the loop without proceeding further
  1853.                    If ( intResultCount >= intRecordRangeTo ) Then
  1854.                         ' max. TO range is crossed/reached ... no need of further looping
  1855.                        Exit For
  1856.                     End If
  1857.                 Next
  1858.  
  1859.                 ' check whether there any pending in the output buffer that has to be
  1860.                ' displayed
  1861.                If intElementCount > 0 Then
  1862.                     ' resize the array so that the buffer is shrinked to its content size
  1863.                    ReDim Preserve arrFinalResults( intElementCount - 1 )
  1864.  
  1865.                         ' Call the display function with required parameters
  1866.                    Call  component.showResults(arrHeader, arrFinalResults, arrMaxLength, _
  1867.                                 strFormat, blnPrintHeader, arrblnDisplay)
  1868.                 Else            ' array bounds checking
  1869.                    If intResultCount = 0 Then
  1870.                           'ie no records found  
  1871.                        If  UBound(arrFilters) >= 0  OR Len(Trim(CStr(strRange))) > 0 Then
  1872.                             ' message no records present  if  filter specified  
  1873.                            component.vbPrintf L_InfoNoRecordsInFilter_Message, Array(strFilterLog)
  1874.                         Else
  1875.                             'message  no records present if filter not  specified
  1876.                            component.vbPrintf L_InfoNoRecords_Message, Array(strFilterLog)
  1877.                         End If
  1878.  
  1879.                     End If ' intResultCount = 0
  1880.  
  1881.                 End If ' array bounds checking
  1882.            End If
  1883.         Else    
  1884.                         'message  no records present
  1885.                        component.vbPrintf L_InfoNoRecords_Message, Array(arrKeyName(intLoopCount))
  1886.         End If
  1887.  
  1888.         ' re-initialize all the needed variables
  1889.        intResultCount = 0
  1890.         Set objEnumerator = Nothing
  1891.         intLoopCount = intLoopCount + 1
  1892.  
  1893.         'blank line before end of the Next Each Log  file details
  1894.        WScript.Echo EmptyLine_Text
  1895.  
  1896.     Loop    ' do-while
  1897.  
  1898. End Sub
  1899.  
  1900. '********************************************************************
  1901. '* Function: GetSupportedUserLocale
  1902. '*
  1903. '* Purpose:This function checks if the current locale is supported or not.
  1904. '*
  1905. '* Output:   Returns TRUE or FALSE
  1906. '*
  1907. '********************************************************************
  1908. Private Function GetSupportedUserLocale()
  1909.  
  1910.  ON ERROR RESUME NEXT
  1911.  Err.Clear
  1912.  
  1913. GetSupportedUserLocale =FALSE
  1914.  
  1915. CONST LANG_ARABIC           =  &H01
  1916. CONST LANG_HEBREW         =  &H0d
  1917. CONST LANG_HINDI            =  &H39
  1918. CONST LANG_TAMIL             =  &H49
  1919. CONST LANG_THAI               =  &H1e
  1920. CONST LANG_VIETNAMESE  =  &H2a
  1921.  
  1922. Dim Lcid        'to store LocaleId
  1923.  
  1924. ' get the current locale
  1925. Lcid=GetLocale()
  1926.  
  1927. CONST PRIMARYLANGID = 1023 '0x3ff
  1928.  
  1929. Dim LANGID       'to store LangID
  1930.  
  1931. ' Convert LCID >>>>>>>>>>>>> LANGID
  1932. ' BIT Wise And Operation
  1933. 'formating to compare HEX Value's
  1934. LANGID     = Hex ( Lcid AND   PRIMARYLANGID )
  1935.  
  1936. ' check whether the current locale is supported by our tool or not
  1937. ' if not change the locale to the English which is our default locale
  1938. Select Case LANGID
  1939.  
  1940.     'here to chaeck the values  
  1941.    Case   Hex(LANG_ARABIC),Hex(LANG_HEBREW),Hex(LANG_THAI) ,Hex(LANG_HINDI ),Hex(LANG_TAMIL) ,Hex(LANG_VIETNAMESE)
  1942.  
  1943.              GetSupportedUserLocale =TRUE
  1944.              Exit Function
  1945. End Select
  1946.  
  1947. End Function
  1948.  
  1949.  
  1950. ' ****************************************************************************************
  1951. '* Function : IsWinXP
  1952. '*
  1953. '* Purpose:This function checks if the OS is XP  or Above.  
  1954. '*
  1955. '* Input:    [in]  Objservice     the service object
  1956. '* Output:   Returns TRUE or FALSE
  1957. '*
  1958. ' ****************************************************************************************
  1959.  
  1960. Private Function IsWinXP ( ByVal objService)
  1961.  
  1962.  ON ERROR RESUME NEXT
  1963.  Err.Clear
  1964.  
  1965.     CONST WIN2K_MAJOR_VERSION = 5000
  1966.     CONST WINXP_MAJOR_VERSION = 5001
  1967.  
  1968.     Dim strQuery            ' to store the query to be executed
  1969.    Dim objEnum             ' collection object
  1970.    Dim objInstance         ' instance object
  1971.    Dim strVersion          ' to store the OS version
  1972.    Dim arrVersionElements  ' to store the OS version elements
  1973.    Dim CurrentMajorVersion ' the major version number
  1974.  
  1975.    ISWinXP= FALSE
  1976.  
  1977.     strQuery = "Select * From  Win32_operatingsystem"
  1978.  
  1979.     Set objEnum = objService.ExecQuery(strQuery,"WQL",0,NULL)
  1980.  
  1981.     For each objInstance in objEnum
  1982.         strVersion= objInstance.Version
  1983.     Next
  1984.  
  1985.     ' OS Version : 5.1.xxxx(Whistler), 5.0.xxxx(Win2K)
  1986.    arrVersionElements  = split(strVersion,".")
  1987.     ' converting to major version
  1988.    CurrentMajorVersion = arrVersionElements(0) * 1000 + arrVersionElements(1)
  1989.  
  1990.     ' Determine the OS Type
  1991.    '  WinXP  > Win2K  
  1992.    If CInt(CurrentMajorVersion) >=  CInt(WINXP_MAJOR_VERSION) Then
  1993.               IsWinXP= TRUE
  1994.    End If
  1995.  
  1996. End Function
  1997.  
  1998. '********************************************************************
  1999. '* Sub:     ShowUsage
  2000. '*
  2001. '* Purpose: Shows the correct usage to the user.
  2002. '*
  2003. '* Output:  Help messages are displayed on screen.
  2004. '*
  2005. '********************************************************************
  2006.  
  2007. Private Sub ShowUsage ()
  2008.  
  2009.     WScript.Echo EmptyLine_Text    
  2010.     WScript.Echo L_ShowUsageLine01_Text        
  2011.     WScript.Echo L_ShowUsageLine02_Text        
  2012.     WScript.Echo EmptyLine_Text    
  2013.     WScript.Echo L_ShowUsageLine03_Text        
  2014.     WScript.Echo L_ShowUsageLine04_Text        
  2015.     WScript.Echo L_ShowUsageLine05_Text        
  2016.     WScript.Echo EmptyLine_Text    
  2017.     WScript.Echo L_ShowUsageLine06_Text      
  2018.     WScript.Echo L_ShowUsageLine07_Text      
  2019.     WScript.Echo EmptyLine_Text      
  2020.     WScript.Echo L_ShowUsageLine08_Text      
  2021.     WScript.Echo L_ShowUsageLine09_Text      
  2022.     WScript.Echo EmptyLine_Text      
  2023.     WScript.Echo L_ShowUsageLine10_Text      
  2024.     WScript.Echo L_ShowUsageLine11_Text  
  2025.     WScript.Echo EmptyLine_Text      
  2026.     WScript.Echo L_ShowUsageLine12_Text        
  2027.     WScript.Echo L_ShowUsageLine13_Text  
  2028.     WScript.Echo EmptyLine_Text      
  2029.     WScript.Echo L_ShowUsageLine14_Text        
  2030.     WScript.Echo L_ShowUsageLine15_Text        
  2031.     WScript.Echo EmptyLine_Text  
  2032.     WScript.Echo L_ShowUsageLine16_Text      
  2033.     WScript.Echo L_ShowUsageLine17_Text      
  2034.     WScript.Echo L_ShowUsageLine18_Text  
  2035.     WScript.Echo EmptyLine_Text    
  2036.     WScript.Echo L_ShowUsageLine19_Text      
  2037.     WScript.Echo L_ShowUsageLine20_Text  
  2038.     WScript.Echo L_ShowUsageLine21_Text  
  2039.     WScript.Echo L_ShowUsageLine22_Text
  2040.     WScript.Echo L_ShowUsageLine23_Text
  2041.     WScript.Echo EmptyLine_Text
  2042.     WScript.Echo L_ShowUsageLine24_Text      
  2043.     WScript.Echo L_ShowUsageLine25_Text      
  2044.     WScript.Echo L_ShowUsageLine26_Text  
  2045.     WScript.Echo EmptyLine_Text        
  2046.     WScript.Echo L_ShowUsageLine27_Text        
  2047.     WScript.Echo EmptyLine_Text    
  2048.     WScript.Echo L_ShowUsageLine28_Text        
  2049.     WScript.Echo EmptyLine_Text        
  2050.     WScript.Echo L_ShowUsageLine29_Text        
  2051.     WScript.Echo L_ShowUsageLine30_Text      
  2052.     WScript.Echo L_ShowUsageLine31_Text      
  2053.     WScript.Echo L_ShowUsageLine32_Text      
  2054.     WScript.Echo L_ShowUsageLine33_Text      
  2055.     WScript.Echo L_ShowUsageLine34_Text      
  2056.     WScript.Echo L_ShowUsageLine35_Text        
  2057.     WScript.Echo L_ShowUsageLine36_Text        
  2058.     WScript.Echo L_ShowUsageLine37_Text        
  2059.     WScript.Echo L_ShowUsageLine38_Text        
  2060.     WScript.Echo EmptyLine_Text
  2061.     WScript.Echo L_ShowUsageLine39_Text        
  2062.     WScript.Echo L_ShowUsageLine40_Text      
  2063.     WScript.Echo EmptyLine_Text
  2064.     WScript.Echo L_ShowUsageLine41_Text        
  2065.     WScript.Echo L_ShowUsageLine42_Text        
  2066.     WScript.Echo L_ShowUsageLine43_Text        
  2067.     WScript.Echo L_ShowUsageLine44_Text      
  2068.     WScript.Echo L_ShowUsageLine45_Text      
  2069.     WScript.Echo L_ShowUsageLine46_Text      
  2070.     WScript.Echo L_ShowUsageLine47_Text    
  2071.     WScript.Echo L_ShowUsageLine48_Text    
  2072.     WScript.Echo L_ShowUsageLine49_Text    
  2073.     WScript.Echo L_ShowUsageLine50_Text    
  2074.     WScript.Echo L_ShowUsageLine51_Text    
  2075.     WScript.Echo L_ShowUsageLine52_Text    
  2076.     WScript.Echo L_ShowUsageLine53_Text    
  2077.  
  2078. End Sub
  2079.  
  2080. '-----------------------------------------------------------------------------
  2081. '                            End of the Script                                
  2082. '-----------------------------------------------------------------------------
  2083.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement