home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 May / W2KPRK.iso / ras.cab / enabledhcp.vbs < prev    next >
Text File  |  1999-11-04  |  24KB  |  687 lines

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