home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 Special / chip-cd_2001_spec_05.zip / spec_05 / ras.cab / checkbios.vbs < prev    next >
Text File  |  1999-11-04  |  25KB  |  703 lines

  1. '********************************************************************
  2. '*
  3. '* File:           CheckBios.vbs
  4. '* Created:        March 1999
  5. '* Version:        1.0
  6. '*
  7. '*  Main Function:  Displays information on system BIOS.
  8. '*
  9. '*  CheckBios.vbs [/S <server>] [/U <username>] [/W <password>] 
  10. '*                [/O <outputfile>]
  11. '*
  12. '* Copyright (C) 1998 Microsoft Corporation
  13. '*
  14. '********************************************************************
  15.  
  16. OPTION EXPLICIT
  17.  
  18.     'Define constants
  19.     CONST CONST_ERROR                   = 0
  20.     CONST CONST_WSCRIPT                 = 1
  21.     CONST CONST_CSCRIPT                 = 2
  22.     CONST CONST_SHOW_USAGE              = 3
  23.     CONST CONST_PROCEED                 = 4
  24.  
  25.     'Declare variables
  26.     Dim intOpMode, i
  27.     Dim strServer, strUserName, strPassword, strOutputFile
  28.     Dim blnVerbose 
  29.  
  30.     'Make sure the host is csript, if not then abort
  31.     VerifyHostIsCscript()
  32.  
  33.     'Parse the command line
  34.     intOpMode = intParseCmdLine(strServer     ,  _
  35.                                 strUserName   ,  _
  36.                                 strPassword   ,  _
  37.                                 strOutputFile    )
  38.  
  39.     Select Case intOpMode
  40.  
  41.         Case CONST_SHOW_USAGE
  42.             Call ShowUsage()
  43.  
  44.         Case CONST_PROCEED                 
  45.             Call CheckBios(strServer     , _
  46.                            strOutputFile , _
  47.                            strUserName   , _
  48.                            strPassword     )
  49.  
  50.         Case CONST_ERROR
  51.             'Do Nothing
  52.  
  53.         Case Else                    'Default -- should never happen
  54.             Call Wscript.Echo("Error occurred in passing parameters.")
  55.  
  56.     End Select
  57.  
  58. '********************************************************************
  59. '* End of Script
  60. '********************************************************************
  61.  
  62. '********************************************************************
  63. '*
  64. '* Sub CheckBios
  65. '*
  66. '* Purpose: Displays information on system BIOS.
  67. '*
  68. '* Input:   strServer           a machine name
  69. '*          strOutputFile       an output file name
  70. '*          strUserName         the current user's name
  71. '*          strPassword         the current user's password
  72. '*
  73. '* Output:  Results are either printed on screen or saved in strOutputFile.
  74. '*
  75. '********************************************************************
  76. Private Sub CheckBios(strServer  ,  _
  77.                       OutputFile ,  _
  78.                       strUserName,  _
  79.                       strPassword   )
  80.  
  81.     ON ERROR RESUME NEXT
  82.  
  83.  
  84.     Dim objFileSystem, objOutputFile, objService, objSet, obj, objInst
  85.     Dim strLine, strClass, strBiosCharacteristic
  86.  
  87.     'Open a text file for output if the file is requested
  88.     If Not IsEmpty(strOutputFile) Then
  89.         If (NOT blnOpenFile(strOutputFile, objOutputFile)) Then
  90.             Call Wscript.Echo ("Could not open an output file.")
  91.             Exit Sub
  92.         End If
  93.     End If
  94.  
  95.     'Establish a connection with the server.
  96.     If blnConnect("root\cimv2" , _
  97.                    strUserName , _
  98.                    strPassword , _
  99.                    strServer   , _
  100.                    objService  ) Then
  101.         Call Wscript.Echo("")
  102.         Call Wscript.Echo("Please check the server name, " _
  103.                         & "credentials and WBEM Core.")
  104.         Exit Sub
  105.     End If
  106.  
  107.     'Display Win32_Bios information
  108.     strClass = "Win32_Bios"
  109.     Set objSet = objService.InstancesOf(strClass)
  110.     If blnErrorOccurred ("obtaining the "& strClass) Then Exit Sub
  111.     WriteLine vbCRLF & CStr(objSet.Count) & " instance(s) of " & strClass & _
  112.             " on " & strServer & ":", objOutputFile
  113.  
  114.     strBiosCharacteristic = Array( _
  115.      "Reserved","Reserved","Unknown", _
  116.      "BIOS Characteristics Not Supported",_
  117.      "ISA is supported","MCA is supported","EISA is supported", _
  118.      "PCI is supported", "PC Card (PCMCIA) is supported", _
  119.      "Plug and Play is supported","APM is supported", _
  120.      "BIOS is Upgradeable (Flash)","BIOS shadowing is allowed", _
  121.      "VL-VESA is supported", "ESCD support is available", _
  122.      "Boot from CD is supported","Selectable Boot is supported",_
  123.      "BIOS ROM is socketed ","Boot From PC Card (PCMCIA) is supported",_
  124.      "EDD (Enhanced Disk Drive) Specification is supported",_
  125.      "Int 13h - Japanese Floppy for NEC 9800 1.2mb (3.5"", 1k Bytes/Sector," _
  126.        & " 360 RPM) is supported",_
  127.      "Int 13h - Japanese Floppy for Toshiba 1.2mb " _
  128.        & "(3.5"", 360 RPM) is supported",_
  129.      "Int 13h - 5.25"" / 360 KB Floppy Services are supported",_
  130.      "Int 13h - 5.25"" /1.2MB Floppy Services are supported",_
  131.      "Int 13h - 3.5"" / 720 KB Floppy Services are  supported",_
  132.      "Int 13h - 3.5"" / 2.88 MB Floppy Services are supported",_
  133.      "Int 5h, Print Screen Service is supported", _
  134.      "Int 9h, 8042 Keyboard services are supported",_
  135.      "Int 14h, Serial Services are supported", _
  136.      "Int 17h, Printer Services are supported",_
  137.      "Int 10h, CGA/Mono Video Services are supported", _
  138.      "NEC PC-98","ACPI supported",_
  139.      "USB Legacy is supported","AGP is supported","I2O boot is supported",_
  140.      "LS-120 boot is supported","ATAPI ZIP Drive boot is supported", _
  141.      "1394 boot is supported", "Smart Battery supported"_
  142.     )
  143.   
  144.     For Each obj In objSet
  145.  
  146.         WriteLine Replace (Space(79), " ", "-"), objOutputFile
  147.  
  148.         'Win32_Bios Properties
  149.         WriteLine "Version:               "& obj.Version                      _
  150.                    , objOutputFile
  151.         WriteLine "ReleaseDate:           "& strFormatMOFTime(obj.ReleaseDate)_
  152.                    , objOutputFile
  153.         WriteLine "Name:                  "& obj.Name                         _
  154.                    , objOutputFile
  155.         WriteLine "PrimaryBIOS:           "& strYesOrNo (obj.PrimaryBIOS)     _
  156.                    , objOutputFile
  157.         WriteLine "SoftwareElementState:  "& CStr(obj.SoftwareElementState)   _
  158.                    , objOutputFile
  159.         WriteLine "TargetOperatingSystem: "& CStr(obj.TargetOperatingSystem)  _
  160.                    , objOutputFile
  161.         WriteLine "OtherTargetOS:         "& obj.OtherTargetOS                _
  162.                    , objOutputFile
  163.         WriteLine "Status:                "& obj.Status                       _
  164.                    , objOutputFile
  165.  
  166.         UBound(obj.BiosCharacteristics)
  167.         If Err.Number Then
  168.             Err.Clear
  169.         Else
  170.  
  171.             WriteLine"BiosCharacteristics:", objOutputFile
  172.  
  173.             For i = 0 to UBound (obj.BiosCharacteristics)
  174.                 WriteLine Space(2) & strBiosCharacteristic _
  175.                 (obj.BiosCharacteristics(i)), objOutputFile
  176.             Next 
  177.  
  178.         End If
  179.  
  180.     Next
  181.  
  182.     If IsObject(objOutputFile) Then
  183.         objOutputFile.Close
  184.         Call Wscript.Echo ("Results are saved in file " & strOutputFile & ".")
  185.     End If
  186.  
  187. End Sub
  188.  
  189. '********************************************************************
  190. '*
  191. '* Function intParseCmdLine()
  192. '*
  193. '* Purpose: Parses the command line.
  194. '* Input:   
  195. '*
  196. '* Output:  strServer         a remote server ("" = local server")
  197. '*          strUserName       the current user's name
  198. '*          strPassword       the current user's password
  199. '*          strOutputFile     an output file name
  200. '*
  201. '********************************************************************
  202. Private Function intParseCmdLine( ByRef strServer,        _
  203.                                   ByRef strUserName,      _
  204.                                   ByRef strPassword,      _
  205.                                   ByRef strOutputFile     )
  206.  
  207.     ON ERROR RESUME NEXT
  208.  
  209.     Dim strFlag
  210.     Dim intState, intArgIter
  211.     Dim objFileSystem
  212.  
  213.     If Wscript.Arguments.Count > 0 Then
  214.         strFlag = Wscript.arguments.Item(0)
  215.     End If
  216.  
  217.     If IsEmpty(strFlag) Then                'No arguments have been received
  218.         intParseCmdLine = CONST_PROCEED
  219.         Exit Function
  220.     End If
  221.  
  222.     'Check if the user is asking for help or is just confused
  223.     If (strFlag="help") OR (strFlag="/h") OR (strFlag="\h") OR (strFlag="-h") _
  224.         OR (strFlag = "\?") OR (strFlag = "/?") OR (strFlag = "?") _ 
  225.         OR (strFlag="h") Then
  226.         intParseCmdLine = CONST_SHOW_USAGE
  227.         Exit Function
  228.     End If
  229.  
  230.     'Retrieve the command line and set appropriate variables
  231.      intArgIter = 0
  232.     Do While intArgIter <= Wscript.arguments.Count - 1
  233.         Select Case Left(LCase(Wscript.arguments.Item(intArgIter)),2)
  234.   
  235.             Case "/s"
  236.                 If Not blnGetArg("Server", strServer, intArgIter) Then
  237.                     intParseCmdLine = CONST_ERROR
  238.                     Exit Function
  239.                 End If
  240.                 intArgIter = intArgIter + 1
  241.  
  242.             Case "/o"
  243.                 If Not blnGetArg("Output File", strOutputFile, intArgIter) Then
  244.                     intParseCmdLine = CONST_ERROR
  245.                     Exit Function
  246.                 End If
  247.                 intArgIter = intArgIter + 1
  248.  
  249.             Case "/u"
  250.                 If Not blnGetArg("User Name", strUserName, intArgIter) Then
  251.                     intParseCmdLine = CONST_ERROR
  252.                     Exit Function
  253.                 End If
  254.                 intArgIter = intArgIter + 1
  255.  
  256.             Case "/w"
  257.                 If Not blnGetArg("User Password", strPassword, intArgIter) Then
  258.                     intParseCmdLine = CONST_ERROR
  259.                     Exit Function
  260.                 End If
  261.                 intArgIter = intArgIter + 1
  262.  
  263.             Case Else 'We shouldn't get here
  264.                 Call Wscript.Echo("Invalid or misplaced parameter: " _
  265.                    & Wscript.arguments.Item(intArgIter) & vbCRLF _
  266.                    & "Please check the input and try again," & vbCRLF _
  267.                    & "or invoke with '/?' for help with the syntax.")
  268.                 Wscript.Quit
  269.  
  270.         End Select
  271.  
  272.     Loop '** intArgIter <= Wscript.arguments.Count - 1
  273.  
  274.     If IsEmpty(intParseCmdLine) Then _
  275.         intParseCmdLine = CONST_PROCEED
  276.  
  277. End Function
  278.  
  279. '********************************************************************
  280. '*
  281. '* Sub ShowUsage()
  282. '*
  283. '* Purpose: Shows the correct usage to the user.
  284. '*
  285. '* Input:   None
  286. '*
  287. '* Output:  Help messages are displayed on screen.
  288. '*
  289. '********************************************************************
  290. Private Sub ShowUsage()
  291.  
  292.     Wscript.Echo ""
  293.     Wscript.Echo "Displays information on system BIOS."
  294.     Wscript.Echo ""
  295.     Wscript.Echo "SYNTAX:"
  296.     Wscript.Echo "  CheckBios.vbs [/S <server>] [/U <username>]" _
  297.                 &" [/W <password>]"
  298.     Wscript.Echo "  [/O <outputfile>]"
  299.     Wscript.Echo ""
  300.     Wscript.Echo "PARAMETER SPECIFIERS:"
  301.     Wscript.Echo "   server        A machine name."
  302.     Wscript.Echo "   username      The current user's name."
  303.     Wscript.Echo "   password      Password of the current user."
  304.     Wscript.Echo "   outputfile    The output file name."
  305.     Wscript.Echo ""
  306.     Wscript.Echo "EXAMPLE:"
  307.     Wscript.Echo "1. cscript CheckBios.vbs"
  308.     Wscript.Echo "   Get the bios information for the current machine."
  309.     Wscript.Echo "2. cscript CheckBios.vbs /S MyMachine2"
  310.     Wscript.Echo "   Get the bios information for the machine MyMachine2."
  311.  
  312. End Sub
  313.  
  314. '********************************************************************
  315. '* General Routines
  316. '********************************************************************
  317.  
  318. '********************************************************************
  319. '*
  320. '* Function strFormatMOFTime(strDate)
  321. '*
  322. '* Purpose: Formats the date in WBEM to a readable Date
  323. '*
  324. '* Input:   blnB    A WBEM Date
  325. '*
  326. '* Output:  a string 
  327. '*
  328. '********************************************************************
  329.  
  330. Private Function strFormatMOFTime(strDate)
  331.     Dim str
  332.     str = Mid(strDate,1,4) & "-" _
  333.            & Mid(strDate,5,2) & "-" _
  334.            & Mid(strDate,7,2) & ", " _
  335.            & Mid(strDate,9,2) & ":" _
  336.            & Mid(strDate,11,2) & ":" _
  337.            & Mid(strDate,13,2)
  338.     strFormatMOFTime = str
  339. End Function
  340.  
  341. '********************************************************************
  342. '*
  343. '* Function strPackString()
  344. '*
  345. '* Purpose: Attaches spaces to a string to increase the length to intWidth.
  346. '*
  347. '* Input:   strString   a string
  348. '*          intWidth    the intended length of the string
  349. '*          blnAfter    Should spaces be added after the string?
  350. '*          blnTruncate specifies whether to truncate the string or not if
  351. '*                      the string length is longer than intWidth
  352. '*
  353. '* Output:  strPackString is returned as the packed string.
  354. '*
  355. '********************************************************************
  356. Private Function strPackString( ByVal strString, _
  357.                                 ByVal intWidth,  _
  358.                                 ByVal blnAfter,  _
  359.                                 ByVal blnTruncate)
  360.  
  361.     ON ERROR RESUME NEXT
  362.  
  363.     intWidth      = CInt(intWidth)
  364.     blnAfter      = CBool(blnAfter)
  365.     blnTruncate   = CBool(blnTruncate)
  366.  
  367.     If Err.Number Then
  368.         Call Wscript.Echo ("Argument type is incorrect!")
  369.         Err.Clear
  370.         Wscript.Quit
  371.     End If
  372.  
  373.     If IsNull(strString) Then
  374.         strPackString = "null" & Space(intWidth-4)
  375.         Exit Function
  376.     End If
  377.  
  378.     strString = CStr(strString)
  379.     If Err.Number Then
  380.         Call Wscript.Echo ("Argument type is incorrect!")
  381.         Err.Clear
  382.         Wscript.Quit
  383.     End If
  384.  
  385.     If intWidth > Len(strString) Then
  386.         If blnAfter Then
  387.             strPackString = strString & Space(intWidth-Len(strString))
  388.         Else
  389.             strPackString = Space(intWidth-Len(strString)) & strString & " "
  390.         End If
  391.     Else
  392.         If blnTruncate Then
  393.             strPackString = Left(strString, intWidth-1) & " "
  394.         Else
  395.             strPackString = strString & " "
  396.         End If
  397.     End If
  398.  
  399. End Function
  400.  
  401. '********************************************************************
  402. '* 
  403. '*  Function blnGetArg()
  404. '*
  405. '*  Purpose: Helper to intParseCmdLine()
  406. '* 
  407. '*  Usage:
  408. '*
  409. '*     Case "/s" 
  410. '*       blnGetArg ("server name", strServer, intArgIter)
  411. '*
  412. '********************************************************************
  413. Private Function blnGetArg ( ByVal StrVarName,   _
  414.                              ByRef strVar,       _
  415.                              ByRef intArgIter) 
  416.  
  417.     blnGetArg = False 'failure, changed to True upon successful completion
  418.  
  419.     If Len(Wscript.Arguments(intArgIter)) > 2 then
  420.         If Mid(Wscript.Arguments(intArgIter),3,1) = ":" then
  421.             If Len(Wscript.Arguments(intArgIter)) > 3 then
  422.                 strVar = Right(Wscript.Arguments(intArgIter), _
  423.                          Len(Wscript.Arguments(intArgIter)) - 3)
  424.                 blnGetArg = True
  425.                 Exit Function
  426.             Else
  427.                 intArgIter = intArgIter + 1
  428.                 If intArgIter > (Wscript.Arguments.Count - 1) Then
  429.                     Call Wscript.Echo( "Invalid " & StrVarName & ".")
  430.                     Call Wscript.Echo( "Please check the input and try again.")
  431.                     Exit Function
  432.                 End If
  433.  
  434.                 strVar = Wscript.Arguments.Item(intArgIter)
  435.                 If Err.Number Then
  436.                     Call Wscript.Echo( "Invalid " & StrVarName & ".")
  437.                     Call Wscript.Echo( "Please check the input and try again.")
  438.                     Exit Function
  439.                 End If
  440.  
  441.                 If InStr(strVar, "/") Then
  442.                     Call Wscript.Echo( "Invalid " & StrVarName)
  443.                     Call Wscript.Echo( "Please check the input and try again.")
  444.                     Exit Function
  445.                 End If
  446.  
  447.                 blnGetArg = True 'success
  448.             End If
  449.         Else
  450.             strVar = Right(Wscript.Arguments(intArgIter), _
  451.                      Len(Wscript.Arguments(intArgIter)) - 2)
  452.             blnGetArg = True 'success
  453.             Exit Function
  454.         End If
  455.     Else
  456.         intArgIter = intArgIter + 1
  457.         If intArgIter > (Wscript.Arguments.Count - 1) Then
  458.             Call Wscript.Echo( "Invalid " & StrVarName & ".")
  459.             Call Wscript.Echo( "Please check the input and try again.")
  460.             Exit Function
  461.         End If
  462.  
  463.         strVar = Wscript.Arguments.Item(intArgIter)
  464.         If Err.Number Then
  465.             Call Wscript.Echo( "Invalid " & StrVarName & ".")
  466.             Call Wscript.Echo( "Please check the input and try again.")
  467.             Exit Function
  468.         End If
  469.  
  470.         If InStr(strVar, "/") Then
  471.             Call Wscript.Echo( "Invalid " & StrVarName)
  472.             Call Wscript.Echo( "Please check the input and try again.")
  473.             Exit Function
  474.         End If
  475.         blnGetArg = True 'success
  476.     End If
  477. End Function
  478.  
  479. '********************************************************************
  480. '*
  481. '* Function blnConnect()
  482. '*
  483. '* Purpose: Connects to machine strServer.
  484. '*
  485. '* Input:   strServer       a machine name
  486. '*          strNameSpace    a namespace
  487. '*          strUserName     name of the current user
  488. '*          strPassword     password of the current user
  489. '*
  490. '* Output:  objService is returned  as a service object.
  491. '*          strServer is set to local host if left unspecified
  492. '*
  493. '********************************************************************
  494. Private Function blnConnect(ByVal strNameSpace, _
  495.                             ByVal strUserName,  _
  496.                             ByVal strPassword,  _
  497.                             ByRef strServer,    _
  498.                             ByRef objService)
  499.  
  500.     ON ERROR RESUME NEXT
  501.  
  502.     Dim objLocator, objWshNet
  503.  
  504.     blnConnect = False     'There is no error.
  505.  
  506.     'Create Locator object to connect to remote CIM object manager
  507.     Set objLocator = CreateObject("WbemScripting.SWbemLocator")
  508.     If Err.Number then
  509.         Call Wscript.Echo( "Error 0x" & CStr(Hex(Err.Number)) & _
  510.                            " occurred in creating a locator object." )
  511.         If Err.Description <> "" Then
  512.             Call Wscript.Echo( "Error description: " & Err.Description & "." )
  513.         End If
  514.         Err.Clear
  515.         blnConnect = True     'An error occurred
  516.         Exit Function
  517.     End If
  518.  
  519.     'Connect to the namespace which is either local or remote
  520.     Set objService = objLocator.ConnectServer (strServer, strNameSpace, _
  521.        strUserName, strPassword)
  522.     ObjService.Security_.impersonationlevel = 3
  523.     If Err.Number then
  524.         Call Wscript.Echo( "Error 0x" & CStr(Hex(Err.Number)) & _
  525.                            " occurred in connecting to server " _
  526.            & strServer & ".")
  527.         If Err.Description <> "" Then
  528.             Call Wscript.Echo( "Error description: " & Err.Description & "." )
  529.         End If
  530.         Err.Clear
  531.         blnConnect = True     'An error occurred
  532.     End If
  533.  
  534.     'Get the current server's name if left unspecified
  535.     If IsEmpty(strServer) Then
  536.         Set objWshNet = CreateObject("Wscript.Network")
  537.     strServer     = objWshNet.ComputerName
  538.     End If
  539.  
  540. End Function
  541.  
  542. '********************************************************************
  543. '*
  544. '* Sub      VerifyHostIsCscript()
  545. '*
  546. '* Purpose: Determines which program is used to run this script.
  547. '*
  548. '* Input:   None
  549. '*
  550. '* Output:  If host is not cscript, then an error message is printed 
  551. '*          and the script is aborted.
  552. '*
  553. '********************************************************************
  554. Sub VerifyHostIsCscript()
  555.  
  556.     ON ERROR RESUME NEXT
  557.  
  558.     Dim strFullName, strCommand, i, j, intStatus
  559.  
  560.     strFullName = WScript.FullName
  561.  
  562.     If Err.Number then
  563.         Call Wscript.Echo( "Error 0x" & CStr(Hex(Err.Number)) & " occurred." )
  564.         If Err.Description <> "" Then
  565.             Call Wscript.Echo( "Error description: " & Err.Description & "." )
  566.         End If
  567.         intStatus =  CONST_ERROR
  568.     End If
  569.  
  570.     i = InStr(1, strFullName, ".exe", 1)
  571.     If i = 0 Then
  572.         intStatus =  CONST_ERROR
  573.     Else
  574.         j = InStrRev(strFullName, "\", i, 1)
  575.         If j = 0 Then
  576.             intStatus =  CONST_ERROR
  577.         Else
  578.             strCommand = Mid(strFullName, j+1, i-j-1)
  579.             Select Case LCase(strCommand)
  580.                 Case "cscript"
  581.                     intStatus = CONST_CSCRIPT
  582.                 Case "wscript"
  583.                     intStatus = CONST_WSCRIPT
  584.                 Case Else       'should never happen
  585.                     Call Wscript.Echo( "An unexpected program was used to " _
  586.                                        & "run this script." )
  587.                     Call Wscript.Echo( "Only CScript.Exe or WScript.Exe can " _
  588.                                        & "be used to run this script." )
  589.                     intStatus = CONST_ERROR
  590.                 End Select
  591.         End If
  592.     End If
  593.  
  594.     If intStatus <> CONST_CSCRIPT Then
  595.         Call WScript.Echo( "Please run this script using CScript." & vbCRLF & _
  596.              "This can be achieved by" & vbCRLF & _
  597.              "1. Using ""CScript CheckBios.vbs arguments"" for Windows 95/98 or" _
  598.              & vbCRLF & "2. Changing the default Windows Scripting Host " _
  599.              & "setting to CScript" & vbCRLF & "    using ""CScript " _
  600.              & "//H:CScript //S"" and running the script using" & vbCRLF & _
  601.              "    ""CheckBios.vbs arguments"" for Windows NT/2000." )
  602.         WScript.Quit
  603.     End If
  604.  
  605. End Sub
  606.  
  607. '********************************************************************
  608. '*
  609. '* Sub WriteLine()
  610. '* Purpose: Writes a text line either to a file or on screen.
  611. '* Input:   strMessage  the string to print
  612. '*          objFile     an output file object
  613. '* Output:  strMessage is either displayed on screen or written to a file.
  614. '*
  615. '********************************************************************
  616. Sub WriteLine(ByVal strMessage, ByVal objFile)
  617.  
  618.     On Error Resume Next
  619.     If IsObject(objFile) then        'objFile should be a file object
  620.         objFile.WriteLine strMessage
  621.     Else
  622.         Call Wscript.Echo( strMessage )
  623.     End If
  624.  
  625. End Sub
  626.  
  627. '********************************************************************
  628. '* 
  629. '* Function blnErrorOccurred()
  630. '*
  631. '* Purpose: Reports error with a string saying what the error occurred in.
  632. '*
  633. '* Input:   strIn        string saying what the error occurred in.
  634. '*
  635. '* Output:  displayed on screen 
  636. '* 
  637. '********************************************************************
  638. Private Function blnErrorOccurred (ByVal strIn)
  639.  
  640.     If Err.Number Then
  641.         Call Wscript.Echo( "Error 0x" & CStr(Hex(Err.Number)) & ": " & strIn)
  642.         If Err.Description <> "" Then
  643.             Call Wscript.Echo( "Error description: " & Err.Description)
  644.         End If
  645.         Err.Clear
  646.         blnErrorOccurred = True
  647.     Else
  648.         blnErrorOccurred = False
  649.     End If
  650.  
  651. End Function
  652.  
  653. '********************************************************************
  654. '* 
  655. '* Function blnOpenFile
  656. '*
  657. '* Purpose: Opens a file.
  658. '*
  659. '* Input:   strFileName        A string with the name of the file.
  660. '*
  661. '* Output:  Sets objOpenFile to a FileSystemObject and setis it to 
  662. '*            Nothing upon Failure.
  663. '* 
  664. '********************************************************************
  665. Private Function blnOpenFile(ByVal strFileName, ByRef objOpenFile)
  666.  
  667.     ON ERROR RESUME NEXT
  668.  
  669.     Dim objFileSystem
  670.  
  671.     Set objFileSystem = Nothing
  672.  
  673.     If IsEmpty(strFileName) OR strFileName = "" Then
  674.         blnOpenFile = False
  675.         Set objOpenFile = Nothing
  676.         Exit Function
  677.     End If
  678.  
  679.     'Create a file object
  680.     Set objFileSystem = CreateObject("Scripting.FileSystemObject")
  681.     If blnErrorOccurred("Could not create filesystem object.") Then
  682.         blnOpenFile = False
  683.         Set objOpenFile = Nothing
  684.         Exit Function
  685.     End If
  686.  
  687.     'Open the file for output
  688.     Set objOpenFile = objFileSystem.OpenTextFile(strFileName, 8, True)
  689.     If blnErrorOccurred("Could not open") Then
  690.         blnOpenFile = False
  691.         Set objOpenFile = Nothing
  692.         Exit Function
  693.     End If
  694.     blnOpenFile = True
  695.  
  696. End Function
  697.  
  698. '********************************************************************
  699. '*                                                                  *
  700. '*                           End of File                            *
  701. '*                                                                  *
  702. '********************************************************************
  703.