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

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