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

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