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

  1. '********************************************************************
  2. '*
  3. '* File:           Device.vbs
  4. '* Created:        March 1999
  5. '* Version:        1.0
  6. '*
  7. '*  Main Function:  Controls Devices on a machine.
  8. '*
  9. '*    1.  Device.vbs /L"
  10. '*                   [/S <server>][/U <username>][/W <password>]"
  11. '*                   [/O <outputfile>]"
  12. '*    
  13. '*    2.  Device.vbs /G | /X | /R | /M <StartMode>"
  14. '*                   /D <device>"
  15. '*                   [/S <server>][/U <username>][/W <password>]"
  16. '*                   [/O <outputfile>]"
  17. '*    
  18. '*    3.  Device.vbs /I /D <device> [/N <DisplayName>]"
  19. '*                   [/S <server>][/U <username>][/W <password>]"
  20. '*                   [/O <outputfile>]"
  21. '*
  22. '* Copyright (C) 1999 Microsoft Corporation
  23. '*
  24. '********************************************************************
  25.  
  26. OPTION EXPLICIT
  27.  
  28.     'Define constants
  29.  
  30.     CONST CONST_ERROR                   = 0
  31.     CONST CONST_WSCRIPT                 = 1
  32.     CONST CONST_CSCRIPT                 = 2
  33.     CONST CONST_SHOW_USAGE              = 3
  34.     CONST CONST_PROCEED                 = 4
  35.     CONST CONST_LIST                    = "LIST"
  36.     CONST CONST_STOP                    = "STOP"
  37.     CONST CONST_START                   = "START"
  38.     CONST CONST_MODE                    = "MODE"
  39.     CONST CONST_INSTALL                 = "INSTALL"
  40.     CONST CONST_REMOVE                  = "REMOVE"
  41.     CONST CONST_DEFAULTTASK             = "DEVICE"
  42.  
  43.  
  44.     'Declare variables
  45.     Dim intOpMode,   i
  46.     Dim strServer, strUserName, strPassword, strOutputFile
  47.     Dim strTaskCommand,   strDriverName,    strStartMode,      strDisplayName
  48.     Dim blnDetails
  49.  
  50.     'Make sure the host is csript, if not then abort
  51.     VerifyHostIsCscript()
  52.  
  53.     'Parse the command line
  54.     intOpMode = intParseCmdLine(strServer      ,  _
  55.                                 strUserName    ,  _
  56.                                 strPassword    ,  _
  57.                                 strOutputFile  ,  _
  58.                                 strTaskCommand ,  _
  59.                                 strDriverName  ,  _
  60.                                 strStartMode   ,  _
  61.                                 strDisplayName ,  _
  62.                                 blnDetails        )
  63.  
  64.     Select Case intOpMode
  65.  
  66.         Case CONST_SHOW_USAGE
  67.             Call ShowUsage()
  68.  
  69.         Case CONST_PROCEED
  70.             Call DEVICE(strServer      ,  _
  71.                         strUserName    ,  _
  72.                         strPassword    ,  _
  73.                         strOutputFile  ,  _
  74.                         strTaskCommand ,  _ 
  75.                         strDriverName  ,  _
  76.                         strStartMode   ,  _
  77.                         strDisplayName ,  _
  78.                         blnDetails        )
  79.  
  80.         Case CONST_ERROR
  81.             Call Wscript.Echo("Invalid or missing parameters " _
  82.                & "Please check the input and try again," & vbCRLF _
  83.                & "or invoke with '/?' for help with the syntax.")
  84.             Wscript.Quit
  85.  
  86.         Case Else                    'Default -- should never happen
  87.             Call Wscript.Echo("Error occurred in passing parameters.")
  88.  
  89.     End Select
  90.  
  91. '********************************************************************
  92. '* End of Script
  93. '********************************************************************
  94.  
  95. '********************************************************************
  96. '*
  97. '* Sub DEVICE()
  98. '* Purpose: Controls DEVICEs on a machine.
  99. '* Input:   
  100. '*          strServer          a machine name
  101. '*          strOutputFile      an output file name
  102. '*          strUserName        the current user's name
  103. '*          strPassword        the current user's password
  104. '*          strTaskCommand     one of /list, /start, /stop /install /remove
  105. '*                                    /dependents
  106. '*          strDriverName      name of the DEVICE
  107. '*          strStartMode       start mode of the DEVICE
  108. '*          strDisplayName     Display name for the DEVICE.
  109. '*          blnDetails         Extra information to be displayed on the output
  110. '* Output:  Results are either printed on screen or saved in strOutputFile.
  111. '*
  112. '********************************************************************
  113.  
  114. Private Sub DEVICE(strServer      ,  _
  115.                    strUserName    ,  _
  116.                    strPassword    ,  _
  117.                    strOutputFile  ,  _
  118.                    strTaskCommand ,  _ 
  119.                    strDriverName  ,  _
  120.                    strStartMode   ,  _
  121.                    strDisplayName ,  _
  122.                    blnDetails        )
  123.  
  124.     ON ERROR RESUME NEXT
  125.  
  126.     Dim objFileSystem, objOutputFile, objService
  127.     Dim strQuery
  128.  
  129.  
  130.     'Open a text file for output if the file is requested
  131.     If Not IsEmpty(strOutputFile) Then
  132.         If (NOT blnOpenFile(strOutputFile, objOutputFile)) Then
  133.             Call Wscript.Echo ("Could not open an output file.")
  134.             Exit Sub
  135.         End If
  136.     End If
  137.  
  138.     'Establish a connection with the server.
  139.     If blnConnect("root\cimv2" , _
  140.                    strUserName , _
  141.                    strPassword , _
  142.                    strServer   , _
  143.                    objService  ) Then
  144.         Call Wscript.Echo("")
  145.         Call Wscript.Echo("Please check the server name, " _
  146.                         & "credentials and WBEM Core.")
  147.         Exit Sub
  148.     End If
  149.  
  150.     'Now execute the method.
  151.     Select Case strTaskCommand
  152.  
  153.         Case CONST_LIST
  154.             Call DeviceList(objService, objOutputFile, blnDetails)
  155.         Case CONST_START
  156.             Call DeviceStart(objService, objOutputFile, strDriverName)
  157.         Case CONST_STOP
  158.             Call DeviceStop(objService, objOutputFile, strDriverName)
  159.         Case CONST_MODE
  160.             Call DeviceMode(objService, objOutputFile, strDriverName, _
  161.                             strStartMode)
  162.         Case CONST_INSTALL
  163.             Call DeviceInstall(objService, objOutputFile, strDriverName, _
  164.                                strDisplayName)
  165.         Case CONST_REMOVE
  166.             Call DeviceRemove(objService, objOutputFile, strDriverName)
  167.  
  168.     End Select
  169.  
  170.     If NOT IsEmpty(objOutputFile) Then
  171.         objOutputFile.Close
  172.         Wscript.Echo "Results are saved in file " & strOutputFile & "."
  173.     End If
  174.  
  175.  
  176. End Sub
  177.  
  178. '********************************************************************
  179. '*
  180. '* Sub DeviceStart()
  181. '* Purpose: Starts a driver.
  182. '* Input:   objService         a Device object
  183. '*          objOutputFile      an output file object
  184. '*          strDriverName      name of the Device to be started or stopped
  185. '* Output:  Results are either printed on screen or saved in objOutputFile.
  186. '*
  187. '********************************************************************
  188. Private Sub DeviceStart(objService, objOutputFile, strDriverName)
  189.  
  190.     ON ERROR RESUME NEXT
  191.  
  192.     Dim objEnumerator, objInstance
  193.     Dim strMessage
  194.     Dim intStatus
  195.  
  196.     strMessage        = ""
  197.     
  198.     Set objInstance = objService.Get("Win32_SystemDriver='" &_
  199.                                       strDriverName & "'")
  200.     If Err.Number Then
  201.         If err.number = -2147217406 then ' Invalid Device Name
  202.             call Print("Device " & strDriverName & " is not valid.")
  203.             call Print("Check for valid Device names with the " _
  204.                              & "/LIST switch.")
  205.         Else
  206.             call Print( "Error 0x" & CStr(Hex(Err.Number)) & " occurred in " _
  207.                       & "getting device " & strDriverName & ".")    
  208.             If Err.Description <> "" Then
  209.                  call Print( "Error description: " & Err.Description & ".")
  210.             End If
  211.         End If
  212.         Err.Clear
  213.         Exit Sub
  214.     End If
  215.     If objInstance is nothing Then
  216.         Exit Sub
  217.     Else
  218.         intStatus = objInstance.StartService()
  219.          if blnErrorOccurred("Provider Failure.") Then
  220.             call Print("Device " & strDriverName & " is not valid.")
  221.              Exit Sub
  222.         End If                
  223.         If intStatus = 0 Then
  224.             strMessage = "Succeeded in starting device " & strDriverName & "."
  225.         Else
  226.             strMessage = "Failed to start device " & strDriverName & "."
  227.         End If
  228.         WriteLine strMessage, objOutputFile
  229.     End If
  230.  
  231. End Sub
  232.  
  233. '********************************************************************
  234. '*
  235. '* Sub DeviceStop()
  236. '* Purpose: Stops a Driver.
  237. '* Input:   objService          a Device object
  238. '* Purpose: Starts a driver.
  239. '* Input:   objService         a Device object
  240. '*          objOutputFile      an output file object
  241. '*          strDriverName      name of the Device to be started or stopped
  242. '* Output:  Results are either printed on screen or saved in objOutputFile.
  243. '*
  244. '********************************************************************
  245. Private Sub DeviceStop(objService, objOutputFile, strDriverName)
  246.  
  247.     ON ERROR RESUME NEXT
  248.  
  249.     Dim objEnumerator, objInstance
  250.     Dim strMessage
  251.     Dim intStatus
  252.     
  253.     strMessage        = ""
  254.     
  255.     Set objInstance = objService.Get("Win32_SystemDriver='" _
  256.                                      & strDriverName & "'")
  257.     If Err.Number Then
  258.         If err.number = -2147217406 then ' Invalid Device Name
  259.             call Print("Device " & strDriverName & " is not valid.")
  260.             call Print("Check for valid Device names with the " _
  261.                              & "/LIST switch.")
  262.         Else
  263.             call Print( "Error 0x" & CStr(Hex(Err.Number)) & " occurred in " _
  264.                       & "getting device " & strDriverName & ".")    
  265.             If Err.Description <> "" Then
  266.                  call Print( "Error description: " & Err.Description & ".")
  267.             End If
  268.         End If
  269.         Err.Clear
  270.         Exit Sub
  271.     End If
  272.     If objInstance is nothing Then
  273.         Exit Sub
  274.     Else
  275.         intStatus = objInstance.StopService()
  276.          if blnErrorOccurred("Provider Failure.") Then
  277.             call Print("Check for valid Device names with the /LIST switch.")
  278.             Exit Sub
  279.         End If
  280.         If intStatus = 0 Then
  281.             strMessage = "Succeeded in stopping Driver " & strDriverName & "."
  282.         Else
  283.             strMessage = "Failed to stop Driver " & strDriverName & "."
  284.         End If
  285.         WriteLine strMessage, objOutputFile
  286.     End If
  287.  
  288. End Sub
  289.  
  290. '********************************************************************
  291. '*
  292. '* Sub DeviceMode()
  293. '* Purpose: Sets the startup mode of a device.
  294. '* Input:   objService          a Device object
  295. '*          objOutputFile       an output file object
  296. '*          strDriverName       name of the Device to be started or stopped
  297. '*          strStartMode        The Mode to set the device to
  298. '*
  299. '* Output:  Results are either printed on screen or saved in objOutputFile.
  300. '*
  301. '********************************************************************
  302. Private Sub DeviceMode(objService, objOutputFile, strDriverName, strStartMode)
  303.  
  304.     ON ERROR RESUME NEXT
  305.  
  306.     Dim objEnumerator, objInstance
  307.     Dim strMessage
  308.     Dim intStatus
  309.     
  310.     strMessage        = ""
  311.     
  312.     Set objInstance = objService.Get("Win32_SystemDriver='"& strDriverName&"'")
  313.     If Err.Number Then
  314.         If err.number = -2147217406 then ' Invalid Device Name
  315.             call Print("Device " & strDriverName & " is not valid.")
  316.             call Print("Check for valid Device names with the /LIST switch.")
  317.         Else
  318.             call Print( "Error 0x" & CStr(Hex(Err.Number)) & " occurred in " _
  319.                       & "getting device " & strDriverName & ".")    
  320.             If Err.Description <> "" Then
  321.                  call Print( "Error description: " & Err.Description & ".")
  322.             End If
  323.         End If
  324.         Err.Clear
  325.         Exit Sub
  326.     End If
  327.     If objInstance is nothing Then
  328.         Exit Sub
  329.     Else
  330.         intStatus = objInstance.ChangeStartMode(strStartMode)
  331.          if blnErrorOccurred("Provider Failure.") Then
  332.             Call Print("Check for valid Device names with the /LIST switch.")
  333.             Exit Sub
  334.         End If
  335.         If intStatus = 0 Then
  336.             strMessage = "Succeeded in changing start mode of the Device " _
  337.                           & strDriverName & "."
  338.         Else
  339.             strMessage = "Failed to change the start mode of the Device " _
  340.                           & strDriverName & "."
  341.         End If
  342.         WriteLine strMessage, objOutputFile
  343.     End If
  344.  
  345. End Sub
  346.  
  347. '********************************************************************
  348. '*
  349. '* Sub DeviceInstall()
  350. '* Purpose: Installs a Driver.
  351. '* Input:   objService          a Device object
  352. '*          objOutputFile       an output file object
  353. '*          strDriverName       name of the Device to be started or stopped
  354. '*          strDisplayName      The Name displayed on the driver list
  355. '*
  356. '* Output:  Results are either printed on screen or saved in objOutputFile.
  357. '*
  358. '********************************************************************
  359. Private Sub DeviceInstall(objService    ,  _
  360.                           objOutputFile ,  _
  361.                           strDriverName ,  _
  362.                           strDisplayName   )
  363.  
  364.     ON ERROR RESUME NEXT
  365.  
  366.     Dim objEnumerator, objInstance
  367.     Dim strMessage
  368.     Dim intStatus
  369.     
  370.     strMessage        = ""
  371.     
  372.     Set objInstance = objService.Get("Win32_SystemDriver")
  373.     If Err.Number Then
  374.         call Print( "Error 0x" & CStr(Hex(Err.Number)) & " occurred in " _
  375.                   & "getting Device " & strDriverName & ".")
  376.         If Err.Description <> "" Then
  377.             call Print( "Error description: " & Err.Description & ".")
  378.         End If
  379.         Err.Clear
  380.         Exit Sub
  381.     End If
  382.     If objInstance is Nothing Then
  383.         Exit Sub
  384.     Else
  385.  
  386.         If IsEmpty(strDisplayName) then strDisplayName = strDriverName
  387.  
  388.         intStatus = objInstance.Create(strDriverName, strDisplayName, _
  389.                                        strDriverName)
  390.          if blnErrorOccurred("Provider Failure.") Then
  391.             call Print("Valid Driver name not specified.")
  392.             Exit Sub
  393.         End If
  394.         If intStatus = 0 Then
  395.             strMessage = "Succeeded in creating Device " & strDriverName & "."
  396.         Else
  397.             strMessage = "Failed to create Device " & strDriverName & "."
  398.         End If
  399.         WriteLine strMessage, objOutputFile
  400.     End If
  401.  
  402. End Sub
  403.  
  404. '********************************************************************
  405. '*
  406. '* Sub DeviceRemove()
  407. '* Purpose: Removes a Driver.
  408. '* Input:   objService          a Device object
  409. '*          objOutputFile       an output file object
  410. '*          strDriverName       name of the Device to be started or stopped
  411. '*
  412. '* Output:  Results are either printed on screen or saved in objOutputFile.
  413. '*
  414. '********************************************************************
  415. Private Sub DeviceRemove(objService, objOutputFile, strDriverName)
  416.  
  417.     ON ERROR RESUME NEXT
  418.  
  419.     Dim objEnumerator, objInstance
  420.     Dim strMessage
  421.     Dim intStatus
  422.     
  423.     strMessage        = ""
  424.  
  425.     Set objInstance = objService.Get("Win32_SystemDriver='" _
  426.                                     & strDriverName&"'")
  427.     If Err.Number Then
  428.         If err.number = -2147217406 then ' Invalid Device Name
  429.                 call Print("Device " & strDriverName & " is not valid.")
  430.                 call Print("Check for valid Device names with the " _
  431.                          & "/LIST switch.")
  432.         Else
  433.             call Print( "Error 0x" & CStr(Hex(Err.Number)) & " occurred in " _
  434.                       & "getting device " & strDriverName & ".")    
  435.             If Err.Description <> "" Then
  436.                  call Print( "Error description: " & Err.Description & ".")
  437.             End If
  438.         End If
  439.         Err.Clear
  440.         Exit Sub
  441.     End If
  442.     If objInstance is Nothing Then
  443.         Exit Sub
  444.     Else
  445.         intStatus = objInstance.Delete()
  446.          if blnErrorOccurred("Provider Failure.") Then
  447.             call Print("Valid Driver name not specified.")
  448.             Exit Sub
  449.         End If        
  450.         If intStatus = 0 Then
  451.             strMessage = "Succeeded in deleting Device " & strDriverName & "."
  452.         Else
  453.             strMessage = "Failed to delete Device " & strDriverName & "."
  454.         End If
  455.         WriteLine strMessage, objOutputFile
  456.     End If
  457.             
  458. End Sub
  459.  
  460. '********************************************************************
  461. '*
  462. '* Sub DeviceList()
  463. '* Purpose: Lists all devices.
  464. '* Input:   objService          a Device object
  465. '*          objOutputFile       an output file object
  466. '*          blnDetails          The option to display more information.
  467. '*
  468. '* Output:  Results are either printed on screen or saved in objOutputFile.
  469. '*
  470. '********************************************************************
  471. Private Sub DeviceList(objService, objOutputFile, blnDetails)
  472.  
  473.     ON ERROR RESUME NEXT
  474.  
  475.     Dim objEnumerator, objInstance
  476.     Dim strMessage
  477.     Dim intDeviceNameLength
  478.     ReDim strName(0), strDisplayName(0), strState(0), strStartModeDsp(0)
  479.     ReDim intOrder(0)
  480.  
  481.     'Initialize local variables
  482.     strMessage        = ""
  483.     strName(0)        = ""
  484.     strDisplayName(0) = ""
  485.     strState(0)       = ""
  486.     intOrder(0)       = 0
  487.  
  488.     Set objEnumerator = objService.ExecQuery ( _
  489.                         "Select Name,PathName,State, StartMode From " _
  490.                       & "Win32_SystemDriver",,0)
  491.     If Err.Number Then
  492.         call Print( "Error 0x" & CStr(Hex(Err.Number)) _
  493.                   & " occurred during the query.")
  494.         If Err.Description <> "" Then
  495.             call Print( "Error description: " & Err.Description & ".")
  496.         End If
  497.         Err.Clear
  498.         Exit Sub
  499.     End If
  500.     i = 0
  501.     For Each objInstance in objEnumerator
  502.         If objInstance is nothing Then
  503.             Exit Sub
  504.         Else
  505.             ReDim Preserve strName(i), strDisplayName(i), _
  506.                            strState(i), strStartModeDsp(i), intOrder(i)
  507.             strName(i) = objInstance.Name
  508.             strDisplayName(i) = objInstance.PathName
  509.             strState(i) = objInstance.State
  510.             strStartModeDsp(i) = objInstance.StartMode
  511.             intOrder(i) = i
  512.             i = i + 1
  513.         End If
  514.         If Err.Number Then
  515.             Err.Clear
  516.         End If
  517.     Next
  518.     intDeviceNameLength = 12
  519.     If i > 0 Then
  520.         'Check Spacing
  521.         For i = 0 To UBound(strName)
  522.             If len(strName(i)) > (intDeviceNameLength - 1) then
  523.                 Do until (intDeviceNameLength - 1) > len(strName(i))
  524.                     intDeviceNameLength = intDeviceNameLength + 1
  525.                 Loop
  526.             End If
  527.         Next
  528.  
  529.         'Display the header
  530.         strMessage = Space(2) & strPackString("NAME", intDeviceNameLength, 1, 1)
  531.         strMessage = strMessage & strPackString("STATE", 10, 1, 1)
  532.         strMessage = strMessage & strPackString("STARTUP", 10, 1, 0)
  533.             If BlnDetails = True then
  534.                 strMessage = strMessage & strPackString("PATH NAME", 15, 1, 0) _
  535.                              & vbCRLF
  536.             End IF
  537.         WriteLine strMessage, objOutputFile
  538.         Call SortArray(strName, True, intOrder, 0)
  539.         Call ReArrangeArray(strDisplayName, intOrder)
  540.         Call ReArrangeArray(strState, intOrder)
  541.         Call ReArrangeArray(strStartModeDsp, intOrder)
  542.         For i = 0 To UBound(strName)
  543.             strMessage = Space(2) & strPackString(strName(i), _
  544.                          intDeviceNameLength, 1, 1)
  545.             strMessage = strMessage & strPackString(strState(i), 10, 1, 1)
  546.             strMessage = strMessage & strPackString(strStartModeDsp(i), _
  547.                          10, 1, 0)
  548.             If BlnDetails = True then
  549.                 strMessage = strMessage & strPackString(strDisplayName(i), _
  550.                          15, 1, 0)
  551.             End If
  552.             WriteLine strMessage, objOutputFile
  553.         Next
  554.     Else
  555.         Wscript.Echo "Device not found!"
  556.     End If
  557.  
  558.  
  559. End Sub
  560.  
  561. '********************************************************************
  562. '*
  563. '* Function intParseCmdLine()
  564. '*
  565. '* Purpose: Parses the command line.
  566. '* Input:   
  567. '*
  568. '* Output:  strServer          a remote server ("" = local server")
  569. '*          strUserName        the current user's name
  570. '*          strPassword        the current user's password
  571. '*          strOutputFile      an output file name
  572. '*          strTaskCommand     one of /list, /start, /stop /install /remove
  573. '*                                    /dependents
  574. '*          strDriverName      name of the DEVICE
  575. '*          strStartMode       start mode of the DEVICE
  576. '*          strDisplayName     Display name for the DEVICE.
  577. '*          blnDetails         Extra information to be displayed on the output
  578.  
  579. '*
  580. '********************************************************************
  581. Private Function intParseCmdLine( ByRef strServer      ,  _
  582.                                   ByRef strUserName    ,  _
  583.                                   ByRef strPassword    ,  _
  584.                                   ByRef strOutputFile  ,  _
  585.                                   ByRef strTaskCommand ,  _
  586.                                   ByRef strDriverName  ,  _
  587.                                   ByRef strStartMode   ,  _
  588.                                   ByRef strDisplayName ,  _
  589.                                   ByRef blnDetails        )
  590.  
  591.  
  592.     ON ERROR RESUME NEXT
  593.  
  594.     Dim strFlag
  595.     Dim intState, intArgIter
  596.     Dim objFileSystem
  597.  
  598.     If Wscript.Arguments.Count > 0 Then
  599.         strFlag = Wscript.arguments.Item(0)
  600.     End If
  601.  
  602.     If IsEmpty(strFlag) Then                'No arguments have been received
  603.         intParseCmdLine = CONST_PROCEED
  604.         strTaskCommand = CONST_LIST
  605.         Exit Function
  606.     End If
  607.  
  608.     'Check if the user is asking for help or is just confused
  609.     If (strFlag="help") OR (strFlag="/h") OR (strFlag="\h") OR (strFlag="-h") _
  610.         OR (strFlag = "\?") OR (strFlag = "/?") OR (strFlag = "?") _ 
  611.         OR (strFlag="h") Then
  612.         intParseCmdLine = CONST_SHOW_USAGE
  613.         Exit Function
  614.     End If
  615.  
  616.     'Retrieve the command line and set appropriate variables
  617.      intArgIter = 0
  618.     Do While intArgIter <= Wscript.arguments.Count - 1
  619.         Select Case Left(LCase(Wscript.arguments.Item(intArgIter)),2)
  620.   
  621.             Case "/s"
  622.                 If Not blnGetArg("Server", strServer, intArgIter) Then
  623.                     intParseCmdLine = CONST_ERROR
  624.                     Exit Function
  625.                 End If
  626.                 intArgIter = intArgIter + 1
  627.  
  628.             Case "/o"
  629.                 If Not blnGetArg("Output File", strOutputFile, intArgIter) Then
  630.                     intParseCmdLine = CONST_ERROR
  631.                     Exit Function
  632.                 End If
  633.                 intArgIter = intArgIter + 1
  634.  
  635.             Case "/u"
  636.                 If Not blnGetArg("User Name", strUserName, intArgIter) Then
  637.                     intParseCmdLine = CONST_ERROR
  638.                     Exit Function
  639.                 End If
  640.                 intArgIter = intArgIter + 1
  641.  
  642.             Case "/w"
  643.                 If Not blnGetArg("User Password", strPassword, intArgIter) Then
  644.                     intParseCmdLine = CONST_ERROR
  645.                     Exit Function
  646.                 End If
  647.                 intArgIter = intArgIter + 1
  648.  
  649.             Case "/d"
  650.                 If Not blnGetArg ("driver name", strDriverName, intArgIter) Then
  651.                     intParseCmdLine = CONST_ERROR
  652.                     Exit Function
  653.                 End If
  654.                 intArgIter = intArgIter + 1
  655.                
  656.             Case "/g"
  657.                 intParseCmdLine = CONST_PROCEED
  658.                 strTaskCommand = CONST_START
  659.                 intArgIter = intArgIter + 1
  660.  
  661.             Case "/x"
  662.                 intParseCmdLine = CONST_PROCEED
  663.                 strTaskCommand = CONST_STOP
  664.                 intArgIter = intArgIter + 1
  665.               
  666.             Case "/m"
  667.                 intParseCmdLine = CONST_PROCEED
  668.                 strTaskCommand = CONST_MODE
  669.                 If Not blnGetArg ("start mode", strStartMode, intArgIter) Then
  670.                     intParseCmdLine = CONST_ERROR
  671.                     Exit Function
  672.                 End If
  673.                 intArgIter = intArgIter + 1
  674.  
  675.             Case "/i"
  676.                 intParseCmdLine = CONST_PROCEED
  677.                 strTaskCommand = CONST_INSTALL
  678.                 intArgIter = intArgIter + 1 
  679.  
  680.             Case "/r"
  681.                 intParseCmdLine = CONST_PROCEED
  682.                 strTaskCommand = CONST_REMOVE
  683.                 intArgIter = intArgIter + 1
  684.  
  685.             Case "/n"
  686.                 If blnGetArg ("display name", strDisplayName, intArgIter) Then
  687.                     intParseCmdLine = CONST_ERROR
  688.                     Exit Function
  689.                 End If
  690.                 intArgIter = intArgIter + 1
  691.               
  692.             Case "/l"
  693.                 intParseCmdLine = CONST_PROCEED
  694.                 strTaskCommand = CONST_LIST
  695.                 intArgIter = intArgIter + 1
  696.  
  697.             Case "/v"
  698.                 blnDetails = True
  699.                 intArgIter = intArgITer + 1
  700.  
  701.             Case Else 'We shouldn't get here
  702.                 Call Wscript.Echo("Invalid or misplaced parameter: " _
  703.                    & Wscript.arguments.Item(intArgIter) & vbCRLF _
  704.                    & "Please check the input and try again," & vbCRLF _
  705.                    & "or invoke with '/?' for help with the syntax.")
  706.                 Wscript.Quit
  707.  
  708.         End Select
  709.  
  710.     Loop '** intArgIter <= Wscript.arguments.Count - 1
  711.  
  712.     If IsEmpty(intParseCmdLine) Then _
  713.         intParseCmdLine = CONST_LIST
  714.  
  715. End Function
  716.  
  717. '********************************************************************
  718. '*
  719. '* Sub ShowUsage()
  720. '*
  721. '* Purpose: Shows the correct usage to the user.
  722. '*
  723. '* Input:   None
  724. '*
  725. '* Output:  Help messages are displayed on screen.
  726. '*
  727. '********************************************************************
  728. Private Sub ShowUsage()
  729.  
  730.     Wscript.Echo ""
  731.     Wscript.Echo "Controls Devices on a machine."
  732.     Wscript.Echo ""
  733.     Wscript.Echo "SYNTAX:"
  734.     Wscript.Echo "1.  Device.vbs /L"
  735.     Wscript.Echo "               [/S <server>][/U <username>][/W <password>]"
  736.     Wscript.Echo "               [/O <outputfile>]"
  737.     Wscript.Echo ""
  738.     Wscript.Echo "2.  Device.vbs /G | /X | /R | /M <StartMode>"
  739.     Wscript.Echo "               /D <device>"
  740.     Wscript.Echo "               [/S <server>][/U <username>][/W <password>]"
  741.     Wscript.Echo "               [/O <outputfile>]"
  742.     Wscript.Echo ""
  743.     Wscript.Echo "3.  Device.vbs /I /D <device> [/N <DisplayName>]"
  744.     Wscript.Echo "               [/S <server>][/U <username>][/W <password>]"
  745.     Wscript.Echo "               [/O <outputfile>]"
  746.     Wscript.Echo ""
  747.     Wscript.Echo "PARAMETER SPECIFIERS:"
  748.     Wscript.Echo "   /L            List all devices"
  749.     Wscript.Echo "   /G            Start a device"
  750.     Wscript.Echo "   /X            Stop a device"
  751.     Wscript.Echo "   /R            Remove a device"
  752.     Wscript.Echo "   /M            Set the device Mode"
  753.     Wscript.Echo "   /I            Install device"
  754.     Wscript.Echo "   StartMode     The Device Startup Setting."
  755.     Wscript.Echo "   device        The Full name and path of the device."
  756.     Wscript.Echo "   DisplayName   The Device name that appears in the" _
  757.                & " directory listing/"
  758.     Wscript.Echo "   server        A machine name."
  759.     Wscript.Echo "   username      The current user's name."
  760.     Wscript.Echo "   password      Password of the current user."
  761.     Wscript.Echo "   outputfile    The output file name."
  762.     Wscript.Echo ""
  763.     Wscript.Echo "EXAMPLE:"
  764.     Wscript.Echo "1. cscript Device.vbs /L /S MyMachine2"
  765.     Wscript.Echo "   Listed installed devices for the machine MyMachine2."
  766.     Wscript.Echo "2. cscript Device.vbs /X /D Beep"
  767.     Wscript.Echo "   Stops device Beep on the current machine."
  768.     Wscript.Echo ""
  769.  
  770. End Sub
  771.  
  772. '********************************************************************
  773. '* General Routines
  774. '********************************************************************
  775.  
  776. '********************************************************************
  777. '*
  778. '* Sub SortArray()
  779. '* Purpose: Sorts an array and arrange another array accordingly.
  780. '* Input:   strArray    the array to be sorted
  781. '*          blnOrder    True for ascending and False for descending
  782. '*          strArray2   an array that has exactly the same number of 
  783. '*                      elements as strArray and will be reordered 
  784. '*                      together with strArray
  785. '*          blnCase     indicates whether the order is case sensitive
  786. '* Output:  The sorted arrays are returned in the original arrays.
  787. '* Note:    Repeating elements are not deleted.
  788. '*
  789. '********************************************************************
  790. Private Sub SortArray(strArray, blnOrder, strArray2, blnCase)
  791.  
  792.     ON ERROR RESUME NEXT
  793.  
  794.     Dim i, j, intUbound
  795.  
  796.     If IsArray(strArray) Then
  797.         intUbound = UBound(strArray)
  798.     Else
  799.         call Print( "Argument is not an array!")
  800.         Exit Sub
  801.     End If
  802.  
  803.     blnOrder = CBool(blnOrder)
  804.     blnCase = CBool(blnCase)
  805.     If Err.Number Then
  806.         call Print( "Argument is not a boolean!")
  807.         Exit Sub
  808.     End If
  809.  
  810.     i = 0
  811.     Do Until i > intUbound-1
  812.         j = i + 1
  813.         Do Until j > intUbound
  814.             If blnCase Then     'Case sensitive
  815.                 If (strArray(i) > strArray(j)) and blnOrder Then
  816.                     Swap strArray(i), strArray(j)   'swaps element i and j
  817.                     Swap strArray2(i), strArray2(j)
  818.                 ElseIf (strArray(i) < strArray(j)) and Not blnOrder Then
  819.                     Swap strArray(i), strArray(j)   'swaps element i and j
  820.                     Swap strArray2(i), strArray2(j)
  821.                 ElseIf strArray(i) = strArray(j) Then
  822.                     'Move element j to next to i
  823.                     If j > i + 1 Then
  824.                         Swap strArray(i+1), strArray(j)
  825.                         Swap strArray2(i+1), strArray2(j)
  826.                     End If
  827.                 End If
  828.             Else                 'Not case sensitive
  829.                 If (LCase(strArray(i)) > LCase(strArray(j))) and blnOrder Then
  830.                     Swap strArray(i), strArray(j)   'swaps element i and j
  831.                     Swap strArray2(i), strArray2(j)
  832.                 ElseIf (LCase(strArray(i)) < LCase(strArray(j))) _
  833.                         and Not blnOrder Then
  834.                     Swap strArray(i), strArray(j)   'swaps element i and j
  835.                     Swap strArray2(i), strArray2(j)
  836.                 ElseIf LCase(strArray(i)) = LCase(strArray(j)) Then
  837.                     'Move element j to next to i
  838.                     If j > i + 1 Then
  839.                         Swap strArray(i+1), strArray(j)
  840.                         Swap strArray2(i+1), strArray2(j)
  841.                     End If
  842.                 End If
  843.             End If
  844.             j = j + 1
  845.         Loop
  846.         i = i + 1
  847.     Loop
  848.  
  849. End Sub
  850.  
  851. '********************************************************************
  852. '*
  853. '* Sub Swap()
  854. '* Purpose: Exchanges values of two strings.
  855. '* Input:   strA    a string
  856. '*          strB    another string
  857. '* Output:  Values of strA and strB are exchanged.
  858. '*
  859. '********************************************************************
  860. Private Sub Swap(ByRef strA, ByRef strB)
  861.  
  862.     Dim strTemp
  863.  
  864.     strTemp = strA
  865.     strA = strB
  866.     strB = strTemp
  867.  
  868. End Sub
  869.  
  870. '********************************************************************
  871. '*
  872. '* Sub ReArrangeArray()
  873. '* Purpose: Rearranges one array according to order specified in another array.
  874. '* Input:   strArray    the array to be rearranged
  875. '*          intOrder    an integer array that specifies the order
  876. '* Output:  strArray is returned as rearranged
  877. '*
  878. '********************************************************************
  879. Private Sub ReArrangeArray(strArray, intOrder)
  880.  
  881.     ON ERROR RESUME NEXT
  882.  
  883.     Dim intUBound, i, strTempArray()
  884.  
  885.     If Not (IsArray(strArray) and IsArray(intOrder)) Then
  886.         call Print( "At least one of the arguments is not an array")
  887.         Exit Sub
  888.     End If
  889.  
  890.     intUBound = UBound(strArray)
  891.  
  892.     If intUBound <> UBound(intOrder) Then
  893.         call Print( "The upper bound of these two arrays do not match!")
  894.         Exit Sub
  895.     End If
  896.  
  897.     ReDim strTempArray(intUBound)
  898.  
  899.     For i = 0 To intUBound
  900.         strTempArray(i) = strArray(intOrder(i))
  901.         If Err.Number Then
  902.             call Print( "Error 0x" & CStr(Hex(Err.Number)) & " occurred in " _
  903.                       & "rearranging an array.")
  904.             If Err.Description <> "" Then
  905.                 call Print( "Error description: " & Err.Description & ".")
  906.             End If
  907.             Err.Clear
  908.             Exit Sub
  909.         End If
  910.     Next
  911.  
  912.     For i = 0 To intUBound
  913.         strArray(i) = strTempArray(i)
  914.     Next
  915.  
  916. End Sub
  917.  
  918. '********************************************************************
  919. '*
  920. '* Function strPackString()
  921. '*
  922. '* Purpose: Attaches spaces to a string to increase the length to intWidth.
  923. '*
  924. '* Input:   strString   a string
  925. '*          intWidth    the intended length of the string
  926. '*          blnAfter    Should spaces be added after the string?
  927. '*          blnTruncate specifies whether to truncate the string or not if
  928. '*                      the string length is longer than intWidth
  929. '*
  930. '* Output:  strPackString is returned as the packed string.
  931. '*
  932. '********************************************************************
  933. Private Function strPackString( ByVal strString, _
  934.                                 ByVal intWidth,  _
  935.                                 ByVal blnAfter,  _
  936.                                 ByVal blnTruncate)
  937.  
  938.     ON ERROR RESUME NEXT
  939.  
  940.     intWidth      = CInt(intWidth)
  941.     blnAfter      = CBool(blnAfter)
  942.     blnTruncate   = CBool(blnTruncate)
  943.  
  944.     If Err.Number Then
  945.         Call Wscript.Echo ("Argument type is incorrect!")
  946.         Err.Clear
  947.         Wscript.Quit
  948.     End If
  949.  
  950.     If IsNull(strString) Then
  951.         strPackString = "null" & Space(intWidth-4)
  952.         Exit Function
  953.     End If
  954.  
  955.     strString = CStr(strString)
  956.     If Err.Number Then
  957.         Call Wscript.Echo ("Argument type is incorrect!")
  958.         Err.Clear
  959.         Wscript.Quit
  960.     End If
  961.  
  962.     If intWidth > Len(strString) Then
  963.         If blnAfter Then
  964.             strPackString = strString & Space(intWidth-Len(strString))
  965.         Else
  966.             strPackString = Space(intWidth-Len(strString)) & strString & " "
  967.         End If
  968.     Else
  969.         If blnTruncate Then
  970.             strPackString = Left(strString, intWidth-1) & " "
  971.         Else
  972.             strPackString = strString & " "
  973.         End If
  974.     End If
  975.  
  976. End Function
  977.  
  978. '********************************************************************
  979. '* 
  980. '*  Function blnGetArg()
  981. '*
  982. '*  Purpose: Helper to intParseCmdLine()
  983. '* 
  984. '*  Usage:
  985. '*
  986. '*     Case "/s" 
  987. '*       blnGetArg ("server name", strServer, intArgIter)
  988. '*
  989. '********************************************************************
  990. Private Function blnGetArg ( ByVal StrVarName,   _
  991.                              ByRef strVar,       _
  992.                              ByRef intArgIter) 
  993.  
  994.     blnGetArg = False 'failure, changed to True upon successful completion
  995.  
  996.     If Len(Wscript.Arguments(intArgIter)) > 2 then
  997.         If Mid(Wscript.Arguments(intArgIter),3,1) = ":" then
  998.             If Len(Wscript.Arguments(intArgIter)) > 3 then
  999.                 strVar = Right(Wscript.Arguments(intArgIter), _
  1000.                          Len(Wscript.Arguments(intArgIter)) - 3)
  1001.                 blnGetArg = True
  1002.                 Exit Function
  1003.             Else
  1004.                 intArgIter = intArgIter + 1
  1005.                 If intArgIter > (Wscript.Arguments.Count - 1) Then
  1006.                     Call Wscript.Echo( "Invalid " & StrVarName & ".")
  1007.                     Call Wscript.Echo( "Please check the input and try again.")
  1008.                     Exit Function
  1009.                 End If
  1010.  
  1011.                 strVar = Wscript.Arguments.Item(intArgIter)
  1012.                 If Err.Number Then
  1013.                     Call Wscript.Echo( "Invalid " & StrVarName & ".")
  1014.                     Call Wscript.Echo( "Please check the input and try again.")
  1015.                     Exit Function
  1016.                 End If
  1017.  
  1018.                 If InStr(strVar, "/") Then
  1019.                     Call Wscript.Echo( "Invalid " & StrVarName)
  1020.                     Call Wscript.Echo( "Please check the input and try again.")
  1021.                     Exit Function
  1022.                 End If
  1023.  
  1024.                 blnGetArg = True 'success
  1025.             End If
  1026.         Else
  1027.             strVar = Right(Wscript.Arguments(intArgIter), _
  1028.                      Len(Wscript.Arguments(intArgIter)) - 2)
  1029.             blnGetArg = True 'success
  1030.             Exit Function
  1031.         End If
  1032.     Else
  1033.         intArgIter = intArgIter + 1
  1034.         If intArgIter > (Wscript.Arguments.Count - 1) Then
  1035.             Call Wscript.Echo( "Invalid " & StrVarName & ".")
  1036.             Call Wscript.Echo( "Please check the input and try again.")
  1037.             Exit Function
  1038.         End If
  1039.  
  1040.         strVar = Wscript.Arguments.Item(intArgIter)
  1041.         If Err.Number Then
  1042.             Call Wscript.Echo( "Invalid " & StrVarName & ".")
  1043.             Call Wscript.Echo( "Please check the input and try again.")
  1044.             Exit Function
  1045.         End If
  1046.  
  1047.         If InStr(strVar, "/") Then
  1048.             Call Wscript.Echo( "Invalid " & StrVarName)
  1049.             Call Wscript.Echo( "Please check the input and try again.")
  1050.             Exit Function
  1051.         End If
  1052.         blnGetArg = True 'success
  1053.     End If
  1054. End Function
  1055.  
  1056. '********************************************************************
  1057. '*
  1058. '* Function blnConnect()
  1059. '*
  1060. '* Purpose: Connects to machine strServer.
  1061. '*
  1062. '* Input:   strServer       a machine name
  1063. '*          strNameSpace    a namespace
  1064. '*          strUserName     name of the current user
  1065. '*          strPassword     password of the current user
  1066. '*
  1067. '* Output:  objService is returned  as a service object.
  1068. '*          strServer is set to local host if left unspecified
  1069. '*
  1070. '********************************************************************
  1071. Private Function blnConnect(ByVal strNameSpace, _
  1072.                             ByVal strUserName,  _
  1073.                             ByVal strPassword,  _
  1074.                             ByRef strServer,    _
  1075.                             ByRef objService)
  1076.  
  1077.     ON ERROR RESUME NEXT
  1078.  
  1079.     Dim objLocator, objWshNet
  1080.  
  1081.     blnConnect = False     'There is no error.
  1082.  
  1083.     'Create Locator object to connect to remote CIM object manager
  1084.     Set objLocator = CreateObject("WbemScripting.SWbemLocator")
  1085.     If Err.Number then
  1086.         Call Wscript.Echo( "Error 0x" & CStr(Hex(Err.Number)) & _
  1087.                            " occurred in creating a locator object." )
  1088.         If Err.Description <> "" Then
  1089.             Call Wscript.Echo( "Error description: " & Err.Description & "." )
  1090.         End If
  1091.         Err.Clear
  1092.         blnConnect = True     'An error occurred
  1093.         Exit Function
  1094.     End If
  1095.  
  1096.     'Connect to the namespace which is either local or remote
  1097.     Set objService = objLocator.ConnectServer (strServer, strNameSpace, _
  1098.        strUserName, strPassword)
  1099.     ObjService.Security_.impersonationlevel = 3
  1100.     If Err.Number then
  1101.         Call Wscript.Echo( "Error 0x" & CStr(Hex(Err.Number)) & _
  1102.                            " occurred in connecting to server " _
  1103.            & strServer & ".")
  1104.         If Err.Description <> "" Then
  1105.             Call Wscript.Echo( "Error description: " & Err.Description & "." )
  1106.         End If
  1107.         Err.Clear
  1108.         blnConnect = True     'An error occurred
  1109.     End If
  1110.  
  1111.     'Get the current server's name if left unspecified
  1112.     If IsEmpty(strServer) Then
  1113.         Set objWshNet = CreateObject("Wscript.Network")
  1114.     strServer     = objWshNet.ComputerName
  1115.     End If
  1116.  
  1117. End Function
  1118.  
  1119. '********************************************************************
  1120. '*
  1121. '* Sub      VerifyHostIsCscript()
  1122. '*
  1123. '* Purpose: Determines which program is used to run this script.
  1124. '*
  1125. '* Input:   None
  1126. '*
  1127. '* Output:  If host is not cscript, then an error message is printed 
  1128. '*          and the script is aborted.
  1129. '*
  1130. '********************************************************************
  1131. Sub VerifyHostIsCscript()
  1132.  
  1133.     ON ERROR RESUME NEXT
  1134.  
  1135.     Dim strFullName, strCommand, i, j, intStatus
  1136.  
  1137.     strFullName = WScript.FullName
  1138.  
  1139.     If Err.Number then
  1140.         Call Wscript.Echo( "Error 0x" & CStr(Hex(Err.Number)) & " occurred." )
  1141.         If Err.Description <> "" Then
  1142.             Call Wscript.Echo( "Error description: " & Err.Description & "." )
  1143.         End If
  1144.         intStatus =  CONST_ERROR
  1145.     End If
  1146.  
  1147.     i = InStr(1, strFullName, ".exe", 1)
  1148.     If i = 0 Then
  1149.         intStatus =  CONST_ERROR
  1150.     Else
  1151.         j = InStrRev(strFullName, "\", i, 1)
  1152.         If j = 0 Then
  1153.             intStatus =  CONST_ERROR
  1154.         Else
  1155.             strCommand = Mid(strFullName, j+1, i-j-1)
  1156.             Select Case LCase(strCommand)
  1157.                 Case "cscript"
  1158.                     intStatus = CONST_CSCRIPT
  1159.                 Case "wscript"
  1160.                     intStatus = CONST_WSCRIPT
  1161.                 Case Else       'should never happen
  1162.                     Call Wscript.Echo( "An unexpected program was used to " _
  1163.                                        & "run this script." )
  1164.                     Call Wscript.Echo( "Only CScript.Exe or WScript.Exe can " _
  1165.                                        & "be used to run this script." )
  1166.                     intStatus = CONST_ERROR
  1167.                 End Select
  1168.         End If
  1169.     End If
  1170.  
  1171.     If intStatus <> CONST_CSCRIPT Then
  1172.         Call WScript.Echo( "Please run this script using CScript." & vbCRLF & _
  1173.              "This can be achieved by" & vbCRLF & _
  1174.              "1. Using ""CScript Device.vbs arguments"" for Windows 95/98 or" _
  1175.              & vbCRLF & "2. Changing the default Windows Scripting Host " _
  1176.              & "setting to CScript" & vbCRLF & "    using ""CScript " _
  1177.              & "//H:CScript //S"" and running the script using" & vbCRLF & _
  1178.              "    ""Device.vbs arguments"" for Windows NT/2000." )
  1179.         WScript.Quit
  1180.     End If
  1181.  
  1182. End Sub
  1183.  
  1184. '********************************************************************
  1185. '*
  1186. '* Sub WriteLine()
  1187. '* Purpose: Writes a text line either to a file or on screen.
  1188. '* Input:   strMessage  the string to print
  1189. '*          objFile     an output file object
  1190. '* Output:  strMessage is either displayed on screen or written to a file.
  1191. '*
  1192. '********************************************************************
  1193. Sub WriteLine(ByVal strMessage, ByVal objFile)
  1194.  
  1195.     On Error Resume Next
  1196.     If IsObject(objFile) then        'objFile should be a file object
  1197.         objFile.WriteLine strMessage
  1198.     Else
  1199.         Call Wscript.Echo( strMessage )
  1200.     End If
  1201.  
  1202. End Sub
  1203.  
  1204. '********************************************************************
  1205. '* 
  1206. '* Function blnErrorOccurred()
  1207. '*
  1208. '* Purpose: Reports error with a string saying what the error occurred in.
  1209. '*
  1210. '* Input:   strIn        string saying what the error occurred in.
  1211. '*
  1212. '* Output:  displayed on screen 
  1213. '* 
  1214. '********************************************************************
  1215. Private Function blnErrorOccurred (ByVal strIn)
  1216.  
  1217.     If Err.Number Then
  1218.         Call Wscript.Echo( "Error 0x" & CStr(Hex(Err.Number)) & ": " & strIn)
  1219.         If Err.Description <> "" Then
  1220.             Call Wscript.Echo( "Error description: " & Err.Description)
  1221.         End If
  1222.         Err.Clear
  1223.         blnErrorOccurred = True
  1224.     Else
  1225.         blnErrorOccurred = False
  1226.     End If
  1227.  
  1228. End Function
  1229.  
  1230. '********************************************************************
  1231. '* 
  1232. '* Function blnOpenFile
  1233. '*
  1234. '* Purpose: Opens a file.
  1235. '*
  1236. '* Input:   strFileName        A string with the name of the file.
  1237. '*
  1238. '* Output:  Sets objOpenFile to a FileSystemObject and setis it to 
  1239. '*            Nothing upon Failure.
  1240. '* 
  1241. '********************************************************************
  1242. Private Function blnOpenFile(ByVal strFileName, ByRef objOpenFile)
  1243.  
  1244.     ON ERROR RESUME NEXT
  1245.  
  1246.     Dim objFileSystem
  1247.  
  1248.     Set objFileSystem = Nothing
  1249.  
  1250.     If IsEmpty(strFileName) OR strFileName = "" Then
  1251.         blnOpenFile = False
  1252.         Set objOpenFile = Nothing
  1253.         Exit Function
  1254.     End If
  1255.  
  1256.     'Create a file object
  1257.     Set objFileSystem = CreateObject("Scripting.FileSystemObject")
  1258.     If blnErrorOccurred("Could not create filesystem object.") Then
  1259.         blnOpenFile = False
  1260.         Set objOpenFile = Nothing
  1261.         Exit Function
  1262.     End If
  1263.  
  1264.     'Open the file for output
  1265.     Set objOpenFile = objFileSystem.OpenTextFile(strFileName, 8, True)
  1266.     If blnErrorOccurred("Could not open") Then
  1267.         blnOpenFile = False
  1268.         Set objOpenFile = Nothing
  1269.         Exit Function
  1270.     End If
  1271.     blnOpenFile = True
  1272.  
  1273. End Function
  1274.  
  1275. '********************************************************************
  1276. '*                                                                  *
  1277. '*                           End of File                            *
  1278. '*                                                                  *
  1279. '********************************************************************