home *** CD-ROM | disk | FTP | other *** search
/ Chip 2009 November / Chip_2009.11_CD.iso / I386 / IIS6.CAB / IIS_adsutil.vbs < prev    next >
Encoding:
Text File  |  2001-07-21  |  91.3 KB  |  2,545 lines

  1. ''''''''''''''''''''''''''''''''''''
  2. '
  3. ' ADSUTIL.VBS
  4. '
  5. ' Author: Adam Stone
  6. ' Date:   7/24/97
  7. ' Revision History:
  8. '     Date         Comment
  9. '    7/24/97       Initial version started
  10. '    5/8/98        Bug fixes and ENUM_ALL
  11. '    12/1/98       Fixed display error on list data.
  12. '    7/27/99       AppCreate2 fix (sonaligu)
  13. '    8/5/99        Dont display encrypted data (sonaligu)
  14. ''''''''''''''''''''''''''''''''''''
  15. Option Explicit
  16. On Error Resume Next
  17.  
  18. ''''''''''''''''''
  19. ' Main Script Code
  20. ''''''''''''''''''
  21. Dim ArgObj ' Object which contains the command line argument
  22. Dim Result ' Result of the command function call
  23. Dim Args(10) ' Array that contains all of the non-global arguments
  24. Dim ArgCount ' Tracks the size of the Args array
  25.  
  26. ' Used for string formatting
  27. Dim Spacer
  28. Dim SpacerSize
  29.  
  30. Const IIS_DATA_NO_INHERIT = 0
  31. Const IIS_DATA_INHERIT = 1
  32. Const GENERAL_FAILURE = 2
  33. Const GENERAL_WARNING = 1
  34. Const AppCreate_InProc = 0
  35. Const AppCreate_OutOfProc = 1
  36. Const AppCreate_PooledOutOfProc = 2
  37.  
  38. Const APPSTATUS_NOTDEFINED = 2   
  39. Const APPSTATUS_RUNNING = 1    
  40. Const APPSTATUS_STOPPED = 0    
  41.  
  42. Spacer = "                                " ' Used to format the strings
  43. SpacerSize = Len(Spacer)
  44.  
  45. ' Note: The default execution mode may be under WScript.exe.
  46. ' That would be very annoying since WScript has popups for Echo.
  47. ' So, I want to detect that, and warn the user that it may cause
  48. ' problems.
  49. DetectExeType
  50.  
  51. ' Get the Arguments object
  52. Set ArgObj = WScript.Arguments
  53.  
  54. ' Test to make sure there is at least one command line arg - the command
  55. If ArgObj.Count < 1 Then
  56.         DisplayHelpMessage
  57.         WScript.Quit (GENERAL_FAILURE)
  58. End If
  59.  
  60. '*****************************************************
  61. ' Modified by Matt Nicholson
  62. Dim TargetServer 'The server to be examined/modified
  63. Dim I
  64. For I = 0 To ArgObj.Count - 1
  65.         If LCase(Left(ArgObj.Item(I), 3)) = "-s:" Then
  66.                 TargetServer = Right(ArgObj.Item(I), Len(ArgObj.Item(I)) - 3)
  67.         Else
  68.                 Args(ArgCount) = ArgObj.Item(I)
  69.                 ArgCount = ArgCount + 1
  70.         End If
  71. Next
  72. If Len(TargetServer) = 0 Then
  73.         TargetServer = "localhost"
  74. End If
  75. '*****************************************************
  76.  
  77. ' Call the function associated with the given command
  78. Select Case UCase(Args(0))
  79.     Case "SET"
  80.                 Result = SetCommand()
  81.     Case "CREATE"
  82.                 Result = CreateCommand("")
  83.     Case "DELETE"
  84.                 Result = DeleteCommand()
  85.     Case "GET"
  86.                 Result = GetCommand()
  87.     Case "ENUM"
  88. '                Result = EnumCommand()
  89.                 Result = EnumCommand(False, "")
  90.     Case "ENUM_ALL"
  91. '                Result = EnumAllCommand()
  92.                 Result = EnumCommand(True, "")
  93.     Case "ENUMALL"
  94. '                Result = EnumAllCommand()
  95.                 Result = EnumCommand(True, "")
  96.     Case "COPY"
  97.                 Result = CopyMoveCommand(True)   ' The TRUE means COPY, not MOVE
  98.     Case "MOVE"
  99.                 Result = CopyMoveCommand(False)   ' The FALSE means MOVE, not COPY
  100.     Case "CREATE_VDIR"
  101.                 Result = CreateCommand("IIsWebVirtualDir")
  102.     Case "CREATE_VSERV"
  103.                 Result = CreateCommand("IIsWebServer")
  104.     Case "START_SERVER"
  105.                 Result = StartServerCommand()
  106.     Case "STOP_SERVER"
  107.                 Result = StopServerCommand()
  108.     Case "PAUSE_SERVER"
  109.                 Result = PauseServerCommand()
  110.     Case "CONTINUE_SERVER"
  111.                 Result = ContinueServerCommand()
  112. ' New Stuff being added
  113.         Case "FIND"
  114.                 Result = FindData()
  115.         Case "COPY"
  116.                 WScript.Echo "COPY is not yet supported.  It will be soon."
  117.         Case "APPCREATEINPROC"
  118.                 Result = AppCreateCommand(AppCreate_InProc)
  119.         Case "APPCREATEOUTPROC"
  120.                 Result = AppCreateCommand(AppCreate_OutOfProc)
  121.     Case "APPCREATEPOOLPROC"
  122.         Result = AppCreateCommand(AppCreate_PooledOutOfProc)
  123.         Case "APPDELETE"
  124.                 Result = AppDeleteCommand()
  125.         Case "APPUNLOAD"
  126.                 Result = AppUnloadCommand()
  127.         Case "APPDISABLE"
  128.                 Result = AppDisableCommand()
  129.         Case "APPENABLE"
  130.                 Result = AppEnableCommand()
  131.         Case "APPGETSTATUS"
  132.                 Result = AppGetStatusCommand()
  133.         Case "HELP"
  134.                 DisplayHelpMessageEx
  135.         
  136. ' End New Stuff
  137.  
  138.     Case Else
  139.                 WScript.Echo "Command not recognized: " & Args(0)
  140.                 WScript.Echo "For help, just type ""Cscript.exe adsutil.vbs""."
  141.                 Result = GENERAL_FAILURE
  142.  
  143. End Select
  144.  
  145. WScript.Quit (Result)
  146.  
  147. ''''''''''
  148. ' End Main
  149. ''''''''''
  150.  
  151.  
  152. ''''''''''''''''''''''''''''
  153. '
  154. ' Display Help Message
  155. '
  156. ''''''''''''''''''''''''''''
  157. Sub DisplayHelpMessage()
  158.     WScript.Echo
  159.     WScript.Echo "Usage:"
  160.     WScript.Echo "      ADSUTIL.VBS <cmd> [<path> [<value>]]"
  161.     WScript.Echo
  162.     'WScript.Echo "Note: ADSUTIL only supports the ""no switch"" option of MDUTIL"
  163.     'WScript.Echo
  164.     WScript.Echo "Description:"
  165.     WScript.Echo "IIS K2 administration utility that enables the manipulation with ADSI parameters"
  166.     WScript.Echo
  167.     'WScript.Echo "Supported MDUTIL Commands:"
  168.     WScript.Echo "Supported Commands:"
  169.     WScript.Echo "  GET, SET, ENUM, DELETE, CREATE, COPY, "
  170.     WScript.Echo "  APPCREATEINPROC, APPCREATEOUTPROC, APPCREATEPOOLPROC, APPDELETE, APPUNLOAD, APPGETSTATUS "
  171.     WScript.Echo
  172.     WScript.Echo "Samples:"
  173.     WScript.Echo "  adsutil.vbs GET W3SVC/1/ServerBindings"
  174.     WScript.Echo "  adsutil.vbs SET W3SVC/1/ServerBindings "":81:"""
  175.     WScript.Echo "  adsutil.vbs CREATE W3SVC/1/Root/MyVdir ""IIsWebVirtualDir"""
  176.     WScript.Echo "  adsutil.vbs START_SERVER W3SVC/1"
  177.     WScript.Echo "  adsutil.vbs ENUM /P W3SVC"
  178.         WScript.Echo
  179.         WScript.Echo "For Extended Help type:"
  180.         WScript.Echo "  adsutil.vbs HELP"
  181.  
  182.  
  183. End Sub
  184.  
  185.  
  186.  
  187. ''''''''''''''''''''''''''''
  188. '
  189. ' Display Help Message
  190. '
  191. ''''''''''''''''''''''''''''
  192. Sub DisplayHelpMessageEx()
  193.  
  194.     WScript.Echo
  195.     WScript.Echo "Usage:"
  196.     WScript.Echo "      ADSUTIL.VBS CMD [param param]"
  197.     WScript.Echo
  198.     'WScript.Echo "Note: ADSUTIL only supports the ""no switch"" option of MDUTIL"
  199.     'WScript.Echo
  200.     WScript.Echo "Description:"
  201.     WScript.Echo "IIS K2 administration utility that enables the manipulation with ADSI parameters"
  202.     WScript.Echo
  203.     'WScript.Echo "Standard MDUTIL Commands:"
  204.     WScript.Echo "Standard Commands:"
  205.     WScript.Echo " adsutil.vbs GET      path             - display chosen parameter"
  206.     WScript.Echo " adsutil.vbs SET      path value ...   - assign the new value"
  207.     WScript.Echo " adsutil.vbs ENUM     path [""/P"" ]   - enumerate all parameters for given path"
  208.     WScript.Echo " adsutil.vbs DELETE   path             - delete given path or parameter"
  209.     WScript.Echo " adsutil.vbs CREATE   path [KeyType]   - create given path and assigns it the given KeyType"
  210.     WScript.Echo
  211.     WScript.Echo " adsutil.vbs APPCREATEINPROC  w3svc/1/root - Create an in-proc application"
  212.     WScript.Echo " adsutil.vbs APPCREATEOUTPROC w3svc/1/root - Create an out-proc application"
  213.     WScript.Echo " adsutil.vbs APPCREATEPOOLPROC w3svc/1/root- Create a pooled-proc application" 
  214.     WScript.Echo " adsutil.vbs APPDELETE        w3svc/1/root - Delete the application if there is one"
  215.     WScript.Echo " adsutil.vbs APPUNLOAD        w3svc/1/root - Unload an application from w3svc runtime lookup table."
  216.     WScript.Echo " adsutil.vbs APPDISABLE       w3svc/1/root - Disable an application - appropriate for porting to another machine."
  217.     WScript.Echo " adsutil.vbs APPENABLE        w3svc/1/root - Enable an application - appropriate for importing from another machine."
  218.     WScript.Echo " adsutil.vbs APPGETSTATUS     w3svc/1/root - Get status of the application"
  219.     WScript.Echo
  220.     WScript.Echo "New ADSI Options:"
  221.     WScript.Echo " /P - Valid for ENUM only.  Enumerates the paths only (no data)"
  222.     WScript.Echo " KeyType - Valide for CREATE only.  Assigns the valid KeyType to the path"
  223.     WScript.Echo
  224.     WScript.Echo "Extended ADSUTIL Commands:"
  225.     WScript.Echo " adsutil.vbs FIND             path     - find the paths where a given parameter is set"
  226.     WScript.Echo " adsutil.vbs CREATE_VDIR      path     - create given path as a Virtual Directory"
  227.     WScript.Echo " adsutil.vbs CREATE_VSERV     path     - create given path as a Virtual Server"
  228.     WScript.Echo " adsutil.vbs START_SERVER     path     - starts the given web site"
  229.     WScript.Echo " adsutil.vbs STOP_SERVER      path     - stops the given web site"
  230.     WScript.Echo " adsutil.vbs PAUSE_SERVER     path     - pauses the given web site"
  231.     WScript.Echo " adsutil.vbs CONTINUE_SERVER  path     - continues the given web site"
  232.     WScript.Echo
  233.     WScript.Echo
  234.     WScript.Echo "Samples:"
  235.     WScript.Echo "  adsutil.vbs GET W3SVC/1/ServerBindings"
  236.     WScript.Echo "  adsutil.vbs SET W3SVC/1/ServerBindings "":81:"""
  237.     WScript.Echo "  adsutil.vbs CREATE W3SVC/1/Root/MyVdir ""IIsWebVirtualDir"""
  238.     WScript.Echo "  adsutil.vbs START_SERVER W3SVC/1"
  239.     WScript.Echo "  adsutil.vbs ENUM /P W3SVC"
  240.  
  241.     WScript.Echo "Extended ADSUTIL Commands:"
  242.     WScript.Echo " adsutil.vbs FIND             path     - find the paths where a given parameter is set"
  243.     WScript.Echo " adsutil.vbs CREATE_VDIR      path     - create given path as a Virtual Directory"
  244.     WScript.Echo " adsutil.vbs CREATE_VSERV     path     - create given path as a Virtual Server"
  245.     WScript.Echo " adsutil.vbs START_SERVER     path     - starts the given web site"
  246.     WScript.Echo " adsutil.vbs STOP_SERVER      path     - stops the given web site"
  247.     WScript.Echo " adsutil.vbs PAUSE_SERVER     path     - pauses the given web site"
  248.     WScript.Echo " adsutil.vbs CONTINUE_SERVER  path     - continues the given web site"
  249.     WScript.Echo
  250.     WScript.Echo
  251.     WScript.Echo "Samples:"
  252.     WScript.Echo "  adsutil.vbs GET W3SVC/1/ServerBindings"
  253.     WScript.Echo "  adsutil.vbs SET W3SVC/1/ServerBindings "":81:"""
  254.     WScript.Echo "  adsutil.vbs CREATE W3SVC/1/Root/MyVdir ""IIsWebVirtualDir"""
  255.     WScript.Echo "  adsutil.vbs START_SERVER W3SVC/1"
  256.     WScript.Echo "  adsutil.vbs ENUM /P W3SVC"
  257.  
  258. ' adsutil.vbs ENUM_ALL path             - recursively enumerate all parameters
  259. ' adsutil.vbs COPY     pathsrc pathdst  - copy all from pathsrc to pathdst (will create pathdst)
  260. ' adsutil.vbs SCRIPT   scriptname       - runs the script
  261.  
  262. '  -path has format: {computer}/{service}/{instance}/{URL}/{Parameter}
  263.  
  264. End Sub
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271. '''''''''''''''''''''''''''
  272. '
  273. ' DetectExeType
  274. '
  275. ' This can detect the type of exe the
  276. ' script is running under and warns the
  277. ' user of the popups.
  278. '
  279. '''''''''''''''''''''''''''
  280. Sub DetectExeType()
  281.         Dim ScriptHost
  282.         Dim ShellObject
  283.  
  284.         Dim CurrentPathExt
  285.         Dim EnvObject
  286.  
  287.         Dim RegCScript
  288.         Dim RegPopupType ' This is used to set the pop-up box flags.
  289.                                                 ' I couldn't find the pre-defined names
  290.         RegPopupType = 32 + 4
  291.  
  292.         On Error Resume Next
  293.  
  294.         ScriptHost = WScript.FullName
  295.         ScriptHost = Right(ScriptHost, Len(ScriptHost) - InStrRev(ScriptHost, "\"))
  296.  
  297.         If (UCase(ScriptHost) = "WSCRIPT.EXE") Then
  298.                 WScript.Echo ("This script does not work with WScript.")
  299.  
  300.                 ' Create a pop-up box and ask if they want to register cscript as the default host.
  301.                 Set ShellObject = WScript.CreateObject("WScript.Shell")
  302.                 ' -1 is the time to wait.  0 means wait forever.
  303.                 RegCScript = ShellObject.PopUp("Would you like to register CScript as your default host for VBscript?", 0, "Register CScript", RegPopupType)
  304.                                                                                 
  305.                 If (Err.Number <> 0) Then
  306.                         ReportError ()
  307.                         WScript.Echo "To run this script using CScript, type: ""CScript.exe " & WScript.ScriptName & """"
  308.                         WScript.Quit (GENERAL_FAILURE)
  309.                         WScript.Quit (Err.Number)
  310.                 End If
  311.  
  312.                 ' Check to see if the user pressed yes or no.  Yes is 6, no is 7
  313.                 If (RegCScript = 6) Then
  314.                         ShellObject.RegWrite "HKEY_CLASSES_ROOT\VBSFile\Shell\Open\Command\", "%WINDIR%\System32\CScript.exe //nologo ""%1"" %*", "REG_EXPAND_SZ"
  315.                         ShellObject.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\VBSFile\Shell\Open\Command\", "%WINDIR%\System32\CScript.exe //nologo ""%1"" %*", "REG_EXPAND_SZ"
  316.                         ' Check if PathExt already existed
  317.                         CurrentPathExt = ShellObject.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PATHEXT")
  318.                         If Err.Number = &H80070002 Then
  319.                                 Err.Clear
  320.                                 Set EnvObject = ShellObject.Environment("PROCESS")
  321.                                 CurrentPathExt = EnvObject.Item("PATHEXT")
  322.                         End If
  323.  
  324.                         ShellObject.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PATHEXT", CurrentPathExt & ";.VBS", "REG_SZ"
  325.  
  326.                         If (Err.Number <> 0) Then
  327.                                 ReportError ()
  328.                                 WScript.Echo "Error Trying to write the registry settings!"
  329.                                 WScript.Quit (Err.Number)
  330.                         Else
  331.                                 WScript.Echo "Successfully registered CScript"
  332.                         End If
  333.                 Else
  334.                         WScript.Echo "To run this script type: ""CScript.Exe adsutil.vbs <cmd> <params>"""
  335.                 End If
  336.  
  337.                 Dim ProcString
  338.                 Dim ArgIndex
  339.                 Dim ArgObj
  340.                 Dim Result
  341.  
  342.                 ProcString = "Cscript //nologo " & WScript.ScriptFullName
  343.  
  344.                 Set ArgObj = WScript.Arguments
  345.  
  346.                 For ArgIndex = 0 To ArgCount - 1
  347.                         ProcString = ProcString & " " & Args(ArgIndex)
  348.                 Next
  349.  
  350.                 'Now, run the original executable under CScript.exe
  351.                 Result = ShellObject.Run(ProcString, 0, True)
  352.  
  353.                 WScript.Quit (Result)
  354.         End If
  355.  
  356. End Sub
  357.  
  358.  
  359. ''''''''''''''''''''''''''
  360. '
  361. ' SetCommand Function
  362. '
  363. ' Sets the value of a property in the metabase.
  364. '
  365. ''''''''''''''''''''''''''
  366. Function SetCommand()
  367.         Dim IIsObject
  368.         Dim IIsObjectPath
  369.         Dim IIsSchemaObject
  370.         Dim IIsSchemaPath
  371.         Dim ObjectPath
  372.         Dim ObjectParameter
  373.         Dim MachineName
  374.         Dim ValueIndex
  375.         Dim ValueList
  376.         Dim ValueDisplay
  377.         Dim ValueDisplayLen
  378.         Dim ValueDataType
  379.  
  380.         Dim ValueData
  381.  
  382.         Dim ObjectDataType
  383.  
  384.         On Error Resume Next
  385.  
  386.         SetCommand = 0 ' Assume Success
  387.  
  388.         If ArgCount < 3 Then
  389.                 WScript.Echo "Error: Wrong number of Args for the SET command"
  390.                 WScript.Quit (GENERAL_FAILURE)
  391.         End If
  392.  
  393.         ObjectPath = Args(1)
  394.         SanitizePath ObjectPath
  395.         MachineName = SeparateMachineName(ObjectPath)
  396.         ObjectParameter = SplitParam(ObjectPath)
  397.  
  398.         ' Some Property Types have special needs - like ServerCommand.
  399.         ' Check to see if this is a special command.  If it is, then process it special.
  400.         If (IsSpecialSetProperty(ObjectParameter)) Then
  401.                 SetCommand = DoSpecialSetProp(ObjectPath, ObjectParameter, MachineName)
  402.                 Exit Function
  403.         End If
  404.  
  405.         If ObjectPath = "" Then
  406.                 IIsObjectPath = "IIS://" & MachineName
  407.         Else
  408.                 IIsObjectPath = "IIS://" & MachineName & "/" & ObjectPath
  409.         End If
  410.         Set IIsObject = GetObject(IIsObjectPath)
  411.  
  412.         If (Err.Number <> 0) Then
  413.                 ReportError ()
  414.                 WScript.Echo "Error Trying To Get the Object: " & ObjectPath
  415.                 WScript.Quit (Err.Number)
  416.         End If
  417.  
  418.         ' Get the Schema of the property and determine if it's multivalued
  419.         IIsSchemaPath = "IIS://" & MachineName & "/Schema/" & ObjectParameter
  420.         Set IIsSchemaObject = GetObject(IIsSchemaPath)
  421.  
  422.         If (Err.Number <> 0) Then
  423.                 ReportError ()
  424.                 WScript.Echo "Error Trying To GET the Schema of the property: " & IIsSchemaPath
  425.                 WScript.Quit (Err.Number)
  426.         End If
  427.  
  428.         ObjectDataType = UCase(IIsSchemaObject.Syntax)
  429.         SanitizePath ObjectDataType
  430.  
  431.         Select Case (ObjectDataType)
  432.  
  433.         Case "STRING"
  434.                 ValueList = Args(2)
  435.                 IIsObject.Put ObjectParameter, (ValueList)
  436.  
  437.         Case "EXPANDSZ"
  438.                 ValueList = Args(2)
  439.                 IIsObject.Put ObjectParameter, (ValueList)
  440.  
  441.         Case "INTEGER"
  442.                 ' Added to convert hex values to integers
  443.                 ValueData = Args(2)
  444.  
  445.                 If (UCase(Left(ValueData, 2))) = "0X" Then
  446.                         ValueData = "&h" & Right(ValueData, Len(ValueData) - 2)
  447.                 End If
  448.  
  449.                 ValueList = CLng(ValueData)
  450.                 IIsObject.Put ObjectParameter, (ValueList)
  451.  
  452.         Case "BOOLEAN"
  453.                 ValueList = CBool(Args(2))
  454.                 IIsObject.Put ObjectParameter, (ValueList)
  455.  
  456.         Case "LIST"
  457.                 ReDim ValueList(ArgCount - 3)
  458.                 For ValueIndex = 2 To ArgCount - 1
  459.                         ValueList(ValueIndex - 2) = Args(ValueIndex)
  460.                 Next
  461.  
  462.                 IIsObject.Put ObjectParameter, (ValueList)
  463.  
  464.         Case Else
  465.                 WScript.Echo "Error: Unknown data type in schema: " & IIsSchemaObject.Syntax
  466.  
  467.         End Select
  468.  
  469.         IIsObject.Setinfo
  470.  
  471.         If (Err.Number <> 0) Then
  472.                 ReportError ()
  473.                 WScript.Echo "Error Trying To SET the Property: " & ObjectParameter
  474.                 WScript.Quit (Err.Number)
  475.         End If
  476.  
  477.         ' The function call succeeded, so display the output
  478.         ' Set up the initial part of the display - the property name and data type
  479.         ValueDisplay = ObjectParameter
  480.         ValueDisplayLen = Len(ValueDisplay)
  481.  
  482.         If (ValueDisplayLen < SpacerSize) Then
  483.                 'ValueDisplay = ValueDisplay & (Right (Spacer, SpacerSize - ValueDisplayLen)) & ": " & "(" & TypeName (ValueList) & ") "
  484.                 ValueDisplay = ValueDisplay & (Right(Spacer, SpacerSize - ValueDisplayLen)) & ": " & "(" & ObjectDataType & ") "
  485.         Else
  486.                 ValueDisplay = ValueDisplay & ": " & "(" & TypeName(ValueList) & ") "
  487.         End If
  488.  
  489.         ' Create the rest of the display - The actual data
  490.         If (IIsSchemaObject.MultiValued) Then
  491.                 For ValueIndex = 0 To UBound(ValueList)
  492.                         'WScript.Echo """" & ValueList(ValueIndex) & """"
  493.                         ValueDisplay = ValueDisplay & """" & ValueList(ValueIndex) & """ "
  494.                 Next
  495.         Else
  496.                 If (UCase(IIsSchemaObject.Syntax) = "STRING") Then
  497.                         'WScript.Echo """" & ValueList & """"
  498.             If (IsSecureProperty(ObjectParameter,MachineName) = True) Then
  499.                            ValueDisplay = ValueDisplay & """" & "**********" & """"
  500.             Else
  501.                             ValueDisplay = ValueDisplay & """" & ValueList & """"
  502.             End If
  503.                 Else
  504.                         'WScript.Echo ValueList
  505.                         ValueDisplay = ValueDisplay & ValueList
  506.                 End If
  507.         End If
  508.  
  509.         ' Display the output
  510.         WScript.Echo ValueDisplay
  511.  
  512.         SetCommand = 0 ' Success
  513.  
  514. End Function
  515.  
  516.  
  517. ''''''''''''''''''''''''''
  518. '
  519. ' GetCommand Function
  520. '
  521. ' Gets the value of a property in the metabase.
  522. '
  523. ''''''''''''''''''''''''''
  524. Function GetCommand()
  525.  
  526.         Dim IIsObject
  527.         Dim IIsObjectPath
  528.         Dim IIsSchemaObject
  529.         Dim IIsSchemaPath
  530.         Dim ObjectPath
  531.         Dim ObjectParameter
  532.         Dim MachineName
  533.         Dim ValueIndex
  534.         Dim ValueList
  535.         Dim ValueDisplay
  536.         Dim ValueDisplayLen
  537.         Dim NewObjectparameter
  538.  
  539.         Dim DataPathList
  540.         Dim DataPath
  541.  
  542.         On Error Resume Next
  543.  
  544.         GetCommand = 0 ' Assume Success
  545.  
  546.         If ArgCount <> 2 Then
  547.                 WScript.Echo "Error: Wrong number of Args for the GET command"
  548.                 WScript.Quit (GENERAL_FAILURE)
  549.         End If
  550.  
  551.         ObjectPath = Args(1)
  552.  
  553.         SanitizePath ObjectPath
  554.         MachineName = SeparateMachineName(ObjectPath)
  555.         ObjectParameter = SplitParam(ObjectPath)
  556.  
  557.         NewObjectparameter = MapSpecGetParamName(ObjectParameter)
  558.         ObjectParameter = NewObjectparameter
  559.  
  560.         If (IsSpecialGetProperty(ObjectParameter)) Then
  561.                 GetCommand = DoSpecialGetProp(ObjectPath, ObjectParameter, MachineName)
  562.                 Exit Function
  563.         End If
  564.  
  565.         If ObjectPath = "" Then
  566.                 IIsObjectPath = "IIS://" & MachineName
  567.         Else
  568.                 IIsObjectPath = "IIS://" & MachineName & "/" & ObjectPath
  569.         End If
  570.  
  571.         Set IIsObject = GetObject(IIsObjectPath)
  572.  
  573.         If (Err.Number <> 0) Then
  574.                 ReportError ()
  575.                 WScript.Echo "Error Trying To GET the Object (GetObject Failed): " & ObjectPath
  576.                 WScript.Quit (Err.Number)
  577.         End If
  578.  
  579.         ' Get the Schema of the property and determine if it's multivalued
  580.         IIsSchemaPath = "IIS://" & MachineName & "/Schema/" & ObjectParameter
  581.         Set IIsSchemaObject = GetObject(IIsSchemaPath)
  582.  
  583.         If (Err.Number <> 0) Then
  584.                 ReportError ()
  585.                 WScript.Echo "Error Trying To GET the Schema of the property: " & IIsSchemaPath
  586.                 WScript.Quit (Err.Number)
  587.         End If
  588.  
  589.         ' First, attempt to retrieve the property - this will tell us
  590.         ' if you are even allowed to set the property at this node.
  591.         ' Retrieve the property
  592.         ValueList = IIsObject.Get(ObjectParameter)
  593.         If (Err.Number <> 0) Then
  594.                 ReportError ()
  595.                 WScript.Echo "Error Trying To GET the property: (Get Method Failed) " & ObjectParameter
  596.                 WScript.Echo "  (This property is probably not allowed at this node)"
  597.                 WScript.Quit (Err.Number)
  598.         End If
  599.  
  600.         ' Test to see if the property is ACTUALLY set at this node
  601.         DataPathList = IIsObject.GetDataPaths(ObjectParameter, IIS_DATA_INHERIT)
  602.         If Err.Number <> 0 Then DataPathList = IIsObject.GetDataPaths(ObjectParameter, IIS_DATA_NO_INHERIT)
  603.         Err.Clear
  604.  
  605.         ' If the data is not set anywhere, then stop the madness
  606.         If (UBound(DataPathList) < 0) Then
  607.                 WScript.Echo "The parameter """ & ObjectParameter & """ is not set at this node."
  608.                 WScript.Quit (&H80005006) ' end with property not set error
  609.         End If
  610.  
  611.         DataPath = DataPathList(0)
  612.         SanitizePath DataPath
  613.  
  614.         ' Test to see if the item is actually set HERE
  615.         If UCase(DataPath) <> UCase(IIsObjectPath) Then
  616.                 WScript.Echo "The parameter """ & ObjectParameter & """ is not set at this node."
  617.                 WScript.Quit (&H80005006) ' end with property not set error
  618.         End If
  619.  
  620.         ' Set up the initial part of the display - the property name and data type
  621.         ValueDisplay = ObjectParameter
  622.         ValueDisplayLen = Len(ValueDisplay)
  623.  
  624.         If (ValueDisplayLen < SpacerSize) Then
  625.                 'ValueDisplay = ValueDisplay & (Right (Spacer, SpacerSize - ValueDisplayLen)) & ": " & "(" & TypeName (ValueList) & ") "
  626.                 ValueDisplay = ValueDisplay & (Right(Spacer, SpacerSize - ValueDisplayLen)) & ": " & "(" & UCase(IIsSchemaObject.Syntax) & ") "
  627.         Else
  628.                 ValueDisplay = ValueDisplay & ": " & "(" & TypeName(ValueList) & ") "
  629.         End If
  630.  
  631.         ' Create the rest of the display - The actual data
  632.         If (IIsSchemaObject.MultiValued) Then
  633.                      WScript.Echo ValueDisplay & " (" & UBound (ValueList) + 1 & " Items)"
  634.                 For ValueIndex = 0 To UBound(ValueList)
  635.                         WScript.Echo "  """ & ValueList(ValueIndex) & """"
  636.                         'ValueDisplay = ValueDisplay & """" & ValueList(ValueIndex) & """ "
  637.                 Next
  638.         Else
  639.                 If (UCase(IIsSchemaObject.Syntax) = "STRING") Then
  640.                         If (IsSecureProperty(ObjectParameter,MachineName) = True) Then
  641.                            ValueDisplay = ValueDisplay & """" & "**********" & """"
  642.             Else
  643.                             ValueDisplay = ValueDisplay & """" & ValueList & """"
  644.             End If
  645.                 Else
  646.                         'WScript.Echo ValueList
  647.                         ValueDisplay = ValueDisplay & ValueList
  648.                 End If
  649.                     ' Display the output
  650.                     WScript.Echo ValueDisplay
  651.         End If
  652.  
  653.  
  654.         If (Err.Number <> 0) Then
  655.                 ReportError ()
  656.                 WScript.Echo "Error Trying To GET the Property: " & ObjectParameter
  657.                 WScript.Quit (Err.Number)
  658.         End If
  659.  
  660.         GetCommand = 0 ' Success
  661.  
  662. End Function
  663.  
  664.  
  665. ''''''''''''''''''''''''''
  666. '
  667. ' EnumCommand Function
  668. '
  669. ' Enumerates all properties at a path in the metabase.
  670. '
  671. ''''''''''''''''''''''''''
  672. Function EnumCommand(Recurse, StartPath)
  673.  
  674.         On Error Resume Next
  675.  
  676.         Dim IIsObject
  677.         Dim IIsObjectPath
  678.         Dim IIsSchemaObject
  679.         Dim IIsSchemaPath
  680.         Dim ObjectPath
  681.         Dim MachineName
  682.         Dim ValueIndex
  683.         Dim ValueList
  684.         Dim ValueString
  685.         Dim PropertyName
  686.         Dim PropertyListSet
  687.         Dim PropertyList
  688.         Dim PropertyObjPath
  689.         Dim PropertyObject
  690.         Dim ChildObject
  691.         Dim ChildObjectName
  692.         Dim EnumPathsOnly
  693.         Dim EnumAllData
  694.         Dim ErrMask
  695.  
  696.         Dim PropertyDataType
  697.  
  698.         Dim DataPathList
  699.         Dim DataPath
  700.  
  701.         Dim SpecialResult
  702.  
  703.         Dim PathOnlyOption
  704.         PathOnlyOption = "/P"
  705.  
  706.         EnumCommand = 0 ' Assume Success
  707.         EnumPathsOnly = False ' Assume that the user wants all of the data items
  708.         EnumAllData = False ' Assume that the user wants only the actual data items
  709.  
  710. 'Debug
  711. 'Dim TestObjectPath
  712. 'Dim TestNumber
  713. 'Dim TestIndex
  714. 'Dim SetIndex
  715.  
  716. 'debug
  717. 'WScript.Echo "ArgCount: " & ArgCount
  718. 'For TestIndex = 0 to ArgCount - 1
  719. '       WScript.Echo "Args(" & TestIndex & "): " & Args(TestIndex)
  720. 'Next
  721.  
  722.         If (ArgCount = 1) Then
  723.                 ObjectPath = ""
  724.                 EnumPathsOnly = False
  725.                                 ArgCount = 2
  726.         ElseIf (ArgCount = 2) Then
  727.                 If UCase(Args(1)) = PathOnlyOption Then
  728.                         ObjectPath = ""
  729.                         EnumPathsOnly = True
  730.                 Else
  731.                         ObjectPath = Args(1)
  732.                         EnumPathsOnly = False
  733.                 End If
  734.         ElseIf (ArgCount = 3) Then
  735.  
  736.                 If UCase(Args(1)) = PathOnlyOption Then
  737.                         ObjectPath = Args(2)
  738.                         EnumPathsOnly = True
  739.                 ElseIf UCase(Args(2)) = PathOnlyOption Then
  740.                         ObjectPath = Args(1)
  741.                         EnumPathsOnly = True
  742.                 Else
  743.                         WScript.Echo "Error: Invalid arguments for the ENUM command"
  744.                         WScript.Quit (GENERAL_FAILURE)
  745.                 End If
  746.         Else
  747.                 WScript.Echo "Error: Wrong number of Args for the ENUM command"
  748.                 WScript.Quit (GENERAL_FAILURE)
  749.         End If
  750.  
  751.                 If StartPath <> "" Then ObjectPath = StartPath
  752.  
  753.         SanitizePath ObjectPath
  754.         MachineName = SeparateMachineName(ObjectPath)
  755.  
  756. 'debug
  757. 'WScript.Echo "EnumPathsOnly: " & EnumPathsOnly
  758. 'WScript.Echo "EnumAllData: " & EnumAllData
  759. 'WScript.Echo "ObjectPath: """ & ObjectPath & """"
  760. 'WScript.Echo "Recurse: """ & Recurse & """"
  761. 'WScript.Echo "Last Error: " & Err & " (" & Hex (Err) & "): " & Err.Description
  762. 'WScript.Quit (Err.Number)
  763.  
  764.         IIsObjectPath = "IIS://" & MachineName
  765.         If (ObjectPath <> "") Then
  766.                 IIsObjectPath = IIsObjectPath & "/" & ObjectPath
  767.         End If
  768. 'debug
  769. 'WScript.Echo "IIsObjectPath: " & IIsObjectPath
  770.         Set IIsObject = GetObject(IIsObjectPath)
  771.  
  772.         If (Err.Number <> 0) Then
  773.                 WScript.Echo
  774.                 ReportError ()
  775.                 WScript.Echo "Error Trying To ENUM the Object (GetObject Failed): " & ObjectPath
  776.                 WScript.Quit (Err.Number)
  777.         End If
  778.  
  779.         ' Get the Schema of the object and enumerate through all of the properties
  780.         IIsSchemaPath = IIsObject.Schema
  781.         Set IIsSchemaObject = GetObject(IIsSchemaPath)
  782.  
  783.         If (Err.Number <> 0) Then
  784.                 WScript.Echo
  785.                 ReportError ()
  786.                 WScript.Echo "Error Trying To GET the Schema of the class: " & IIsSchemaPath
  787.                 WScript.Quit (Err.Number)
  788.         End If
  789.  
  790.         ReDim PropertyListSet(1)
  791.         PropertyListSet(0) = IIsSchemaObject.MandatoryProperties
  792.         PropertyListSet(1) = IIsSchemaObject.OptionalProperties
  793.  
  794.         If (Err.Number <> 0) Then
  795.                 WScript.Echo
  796.                 ReportError ()
  797.                 WScript.Echo "Error trying to get the list of properties: " & IIsSchemaPath
  798.                 WScript.Quit (Err.Number)
  799.         End If
  800.  
  801.         ' added by Adam Stone - 5/31/98
  802.         ' This now checks for an empty OptionalProperties list
  803.         If TypeName (PropertyListSet(1)) <> "Variant()" Then
  804.             WScript.Echo
  805.             WScript.Echo "Warning: The optionalproperties list is of an invalid type"
  806.             WScript.Echo
  807.         ElseIf (UBound (PropertyListSet(1)) = -1) Then
  808.             WScript.Echo
  809.             WScript.Echo "Warning: The OptionalProperties list for this node is empty."
  810.             WScript.Echo
  811.         End If
  812.  
  813.  
  814.         If (Not EnumPathsOnly) Then
  815.         For Each PropertyList In PropertyListSet
  816.  
  817.                 For Each PropertyName In PropertyList
  818.                         If Err <> 0 Then
  819.                             Exit For
  820.                         End If
  821.  
  822.                         ' Test to see if the property is even set at this node
  823.                         DataPathList = IIsObject.GetDataPaths(PropertyName, IIS_DATA_INHERIT)
  824.                         If Err.Number <> 0 Then DataPathList = IIsObject.GetDataPaths(PropertyName, IIS_DATA_NO_INHERIT)
  825.                         Err.Clear
  826.  
  827.                         If (UBound(DataPathList) >= 0) Or (EnumAllData) Then
  828.                          DataPath = DataPathList(0)
  829.                          SanitizePath DataPath
  830.                          If (UCase(DataPath) = UCase(IIsObjectPath)) Or (EnumAllData) Then
  831.                          ' If the above statement is true, then the data exists here or the user wants it anyway.
  832.  
  833.                         PropertyObjPath = "IIS://" & MachineName & "/Schema/" & PropertyName
  834.                         Set PropertyObject = GetObject(PropertyObjPath)
  835.  
  836.                         If (Err.Number <> 0) Then
  837.                                 WScript.Echo
  838.                                 ReportError ()
  839.                                 WScript.Echo "Error trying to enumerate the Optional properties (Couldn't Get Property Information): " & PropertyObjPath
  840.                                 WScript.Echo "Last Property Name: " & PropertyName
  841.                                 WScript.Echo "PropertyObjPath: " & PropertyObjPath
  842.                                 'WScript.Quit (Err.Number)
  843.                                 WScript.Echo
  844.                                 EnumCommand = Err.Number
  845.                                 Err.Clear
  846.                         End If
  847.  
  848.                         ValueList = ""
  849.  
  850.                         PropertyDataType = UCase(PropertyObject.Syntax)
  851.                         Select Case PropertyDataType
  852.                                 Case "STRING"
  853.                                         ValueList = IIsObject.Get(PropertyName)
  854.                     If (IsSecureProperty(PropertyName,MachineName) = True) Then
  855.                             WScript.Echo PropertyName & Left(Spacer, Len(Spacer) - Len(PropertyName)) & " : " & "(" & PropertyDataType & ")" & """" & "**********" & """"
  856.                     Else
  857.                                             If (Len(PropertyName) < SpacerSize) Then
  858.                                                     WScript.Echo PropertyName & Left(Spacer, Len(Spacer) - Len(PropertyName)) & ": " & "(" & PropertyDataType & ") """ & ValueList & """"
  859.                                             Else
  860.                                                     WScript.Echo PropertyName & " : " & "(" & PropertyDataType & ")" & """" & ValueList & """"
  861.                                             End If
  862.                     End If
  863.  
  864.                                 Case "EXPANDSZ"
  865.                                         ValueList = IIsObject.Get(PropertyName)
  866.                                         If (Len(PropertyName) < SpacerSize) Then
  867.                                                 WScript.Echo PropertyName & Left(Spacer, Len(Spacer) - Len(PropertyName)) & ": " & "(" & PropertyDataType & ") """ & ValueList & """"
  868.                                         Else
  869.                                                 WScript.Echo PropertyName & " : " & "(" & PropertyDataType & ") """ & ValueList & """"
  870.                                         End If
  871.                                 Case "INTEGER"
  872.                                         ValueList = IIsObject.Get(PropertyName)
  873.                                         If (Len(PropertyName) < SpacerSize) Then
  874.                                                 WScript.Echo PropertyName & Left(Spacer, Len(Spacer) - Len(PropertyName)) & ": " & "(" & PropertyDataType & ") " & ValueList
  875.                                         Else
  876.                                                 WScript.Echo PropertyName & " : " & "(" & PropertyDataType & ") " & ValueList
  877.                                         End If
  878.                                 Case "BOOLEAN"
  879.                                         ValueList = IIsObject.Get(PropertyName)
  880.                                         If (Len(PropertyName) < SpacerSize) Then
  881.                                                 WScript.Echo PropertyName & Left(Spacer, Len(Spacer) - Len(PropertyName)) & ": " & "(" & PropertyDataType & ") " & ValueList
  882.                                         Else
  883.                                                 WScript.Echo PropertyName & " : " & "(" & PropertyDataType & ") " & ValueList
  884.                                         End If
  885.  
  886.                                 Case "LIST"
  887.                                         ValueList = IIsObject.Get(PropertyName)
  888.                                         If (Len(PropertyName) < SpacerSize) Then
  889.                                                 WScript.Echo PropertyName & _
  890.                                                                 Left(Spacer, Len(Spacer) - Len(PropertyName)) & _
  891.                                                                 ": " & "(" & PropertyDataType & ") (" & _
  892.                                                                 (UBound (ValueList) + 1) & " Items)"
  893.                                         Else
  894.                                                 WScript.Echo PropertyName & " : " & "(" & PropertyDataType & ") (" & (UBound (ValueList) + 1) & " Items)"
  895.                                         End If
  896.                                         ValueString = ""
  897.  
  898.                                         For ValueIndex = 0 To UBound(ValueList)
  899.                                                                 WScript.Echo "  """ & ValueList(ValueIndex) & """"
  900.                                         Next
  901.                                                      WScript.Echo
  902.  
  903.                                 Case Else
  904.  
  905.                                         If (IsSpecialGetProperty(PropertyName)) Then
  906.  
  907.                                                 SpecialResult = DoSpecialGetProp(ObjectPath, PropertyName, MachineName)
  908.                                                 Err.Clear
  909.  
  910.                                         Else
  911.                                                 WScript.Echo
  912.                                                 WScript.Echo "DataType: " & """" & PropertyObject.Syntax & """" & " Not Yet Supported on property: " & PropertyName
  913.                                                 ReportError
  914.                                                 WScript.Echo
  915.                                         End If
  916.  
  917.                         End Select
  918.  
  919.                          End If ' End if data exists at the current node
  920.                         End If ' End If data list > 0
  921.  
  922.                         If (Err.Number <> 0) Then
  923.                                 WScript.Echo
  924.                                 ReportError ()
  925.                                 WScript.Echo "Error trying to enumerate the Optional properties (Error trying to get property value): " & PropertyObjPath
  926.                                 WScript.Echo "Last Property Name: " & PropertyName
  927.                                 WScript.Echo "PropertyObjPath: " & PropertyObjPath
  928.                                 ' If there is an ADS error, just ignore it and move on
  929.                                 ' otherwise, quit
  930.                                 If ((Err.Number) >= &H80005000) And ((Err.Number) < &H80006000) Then
  931.                                         Err.Clear
  932.                                         WScript.Echo "Continuing..."
  933.                                 Else
  934.                                         WScript.Quit (Err.Number)
  935.                                 End If
  936.                                 WScript.Echo
  937.                         End If
  938.                 Next
  939.         Next
  940.  
  941.         If (Err.Number <> 0) Then
  942.             WScript.Echo "Error trying to enumerate the properties lists:"
  943.             ReportError ()
  944.             WScript.Echo
  945.             EnumCommand = Err.Number
  946.             Err.Clear
  947.         End If
  948.  
  949.         End If ' End if (Not EnumPathsOnly)
  950.  
  951. 'WScript.Echo "Last Error: " & Err & " (" & Hex (Err) & "): " & Err.Description
  952.         ' Now, enumerate the data paths
  953.         For Each ChildObject In IIsObject
  954.             If (Err.Number <> 0) Then Exit For
  955.  
  956. 'WScript.Echo "Parent Name: " & IIsObject.Name
  957. 'WScript.Echo "Child Name: " & ChildObject.Name
  958. 'WScript.Echo "Last Error: " & Err & " (" & Hex (Err) & "): " & Err.Description
  959. 'Err.Clear
  960.                 ChildObjectName = Right(ChildObject.AdsPath, Len(ChildObject.AdsPath) - 6)
  961.                 ChildObjectName = Right(ChildObjectName, Len(ChildObjectName) - InStr(ChildObjectName, "/") + 1)
  962.                 WScript.Echo "[" & ChildObjectName & "]"
  963.                 If (Recurse = True) And (ChildObjectName <> Args(1)) Then
  964.                         EnumCommand = EnumCommand(True, ChildObjectName)
  965.                 End If
  966.         Next
  967.  
  968.         If (Err.Number <> 0) Then
  969.             WScript.Echo "Error trying to enumerate the child nodes"
  970.             ReportError ()
  971.             WScript.Echo
  972.             EnumCommand = Err.Number
  973.             Err.Clear
  974.         End If
  975.  
  976. WScript.Echo ""
  977.  
  978. End Function
  979.  
  980.  
  981. ''''''''''''''''''''''''''
  982. '
  983. ' Create Function
  984. '
  985. ' Creates a path in the metabase.  An additional parameter that is
  986. ' not found in mdutil is optional.  That is the Object Type (KeyType)
  987. ' If this is not specified, the object type will be assumed to be
  988. ' IIsObject (which, of course, is useless).
  989. '
  990. ''''''''''''''''''''''''''
  991. Function CreateCommand(ObjectTypeParam)
  992.  
  993.         On Error Resume Next
  994.  
  995.         Dim IIsObject
  996.         Dim IIsObjectPath
  997.         Dim IIsObjectRelativePath
  998.         Dim NewObject
  999.         Dim ObjectTypeName
  1000.         Dim ParentObjPath
  1001.         Dim ParentObjSize
  1002.         Dim FullAdsParentPath
  1003.         Dim MachineName
  1004.         Dim OpenErr
  1005.  
  1006.         ' Set the return code - assume success
  1007.         CreateCommand = 0
  1008.  
  1009.         ' Setup the parameters
  1010.         If (ArgCount = 2) Then
  1011.                 If (ObjectTypeParam = "") Then
  1012.                         ObjectTypeName = "IIsObject"
  1013.                 Else
  1014.                         ObjectTypeName = ObjectTypeParam
  1015.                 End If
  1016.         ElseIf (ArgCount = 3) Then
  1017.                 ObjectTypeName = Args(2)
  1018.         Else
  1019.                 WScript.Echo "Error: Wrong number of Args for the CREATE command"
  1020.                 DisplayHelpMessage
  1021.                 WScript.Quit (GENERAL_FAILURE)
  1022.         End If
  1023.  
  1024.         IIsObjectPath = Args(1)
  1025.         SanitizePath IIsObjectPath
  1026.         MachineName = SeparateMachineName(IIsObjectPath)
  1027.  
  1028.         ' Parse the path and determine if the parent exists.
  1029.         ParentObjSize = InStrRev(IIsObjectPath, "/")
  1030.         ParentObjPath = ""
  1031.  
  1032.         If ParentObjSize <> 0 Then
  1033.                 ParentObjPath = Left(IIsObjectPath, ParentObjSize - 1)
  1034.                 IIsObjectRelativePath = Right(IIsObjectPath, Len(IIsObjectPath) - ParentObjSize)
  1035.         Else
  1036.                 IIsObjectRelativePath = IIsObjectPath
  1037.         End If
  1038.  
  1039.         If ParentObjPath <> "" Then
  1040.                 FullAdsParentPath = "IIS://" & MachineName & "/" & ParentObjPath
  1041.         Else
  1042.                 FullAdsParentPath = "IIS://" & MachineName
  1043.         End If
  1044. 'debug
  1045. 'WScript.Echo "Last Error: " & Err.Number
  1046. 'WScript.Echo "MachineName: " & MachineName
  1047. 'WScript.Echo "ParentObjPath: " & ParentObjPath
  1048. 'WScript.Echo "FullAdsParentPath: " & FullAdsParentPath
  1049. 'WScript.Echo "IIsObjectPath: " & IIsObjectPath
  1050. 'WScript.Echo "IIsObjectRelativePath: " & IIsObjectRelativePath
  1051. 'WScript.Echo "ObjectTypeName: " & ObjectTypeName
  1052.  
  1053.         ' First, attempt to open the parent path and add the new path.
  1054.         Set IIsObject = GetObject(FullAdsParentPath)
  1055.         If Err.Number <> 0 Then
  1056.                 OpenErr = Err.Number
  1057.                 OpenErrDesc = Err.Description
  1058.                 Err.Clear
  1059.                 ' Attempt to get the Computer Object (IIS://LocalHost)
  1060.                 Set IIsObject = GetObject("IIS://" & MachineName)
  1061.                 If Err.Number <> 0 Then
  1062.                         WScript.Echo
  1063.                         ReportError ()
  1064.                         WScript.Echo "Error accessing the object: " & IIsObjectPath
  1065.                         WScript.Quit (Err.Number)
  1066.                 End If
  1067.         End If
  1068.  
  1069.         'Now, attempt to add the new object.
  1070.         If (OpenErr <> 0) Then
  1071.                 Set NewObject = IIsObject.Create(ObjectTypeName, IIsObjectPath)
  1072.         Else
  1073.                 Set NewObject = IIsObject.Create(ObjectTypeName, IIsObjectRelativePath)
  1074.         End If
  1075.  
  1076.         If Err.Number <> 0 Then
  1077.                 WScript.Echo
  1078.                 ReportError ()
  1079.                 WScript.Echo "Error creating the object: " & IIsObjectPath
  1080.                 WScript.Quit (Err.Number)
  1081.         End If
  1082.  
  1083.         NewObject.Setinfo
  1084.  
  1085.         If Err.Number <> 0 Then
  1086.                 WScript.Echo
  1087.                 ReportError ()
  1088.                 WScript.Echo "Error creating the object: " & IIsObjectPath
  1089.                 WScript.Quit (Err.Number)
  1090.         End If
  1091.  
  1092.  
  1093.         ' Now, if the parent object was not created, generate a warning.
  1094.         If OpenErr <> 0 Then
  1095.                 WScript.Echo
  1096.                 WScript.Echo "WARNING: The parent path (" & ParentObjPath & ") was not already created."
  1097.                 WScript.Echo "    This means that some of the intermediate objects will not have an accurate"
  1098.                 WScript.Echo "    Object Type. You should fix this by setting the KeyType on the intermediate"
  1099.                 WScript.Echo "    objects."
  1100.                 WScript.Echo
  1101.                 CreateCommand = GENERAL_WARNING
  1102.         End If
  1103.  
  1104.         If UCase(ObjectTypeName) = "IISOBJECT" Then
  1105.                 WScript.Echo
  1106.                 WScript.Echo "WARNING: The Object Type of this object was not specified or was specified as"
  1107.                 WScript.Echo "    IIsObject.  This means that you will not be able to set or get properties"
  1108.                 WScript.Echo "    on the object until the KeyType property is set."
  1109.                 WScript.Echo
  1110.                 CreateCommand = GENERAL_WARNING
  1111.         End If
  1112.  
  1113.         WScript.Echo "created """ & IIsObjectPath & """"
  1114. End Function
  1115.  
  1116. ''''''''''''''''''''''''''
  1117. '
  1118. ' Delete Function
  1119. '
  1120. ' Deletes a path in the metabase.
  1121. '
  1122. ''''''''''''''''''''''''''
  1123. Function DeleteCommand()
  1124.  
  1125.         On Error Resume Next
  1126.  
  1127.         Dim IIsObject
  1128.         Dim IIsObjectPath
  1129.  
  1130.         Dim ObjectPath
  1131.         Dim ObjectParam
  1132.         Dim MachineName
  1133.  
  1134.         Dim DummyVariant
  1135.         Dim DeletePathOnly
  1136.         ReDim DummyVariant(0)
  1137.         DummyVariant(0) = "Crap"
  1138.  
  1139.         ' Set the return code - assume success
  1140.         DeleteCommand = 0
  1141.  
  1142.         ' Setup the parameters
  1143.         If (ArgCount <> 2) Then
  1144.                 WScript.Echo "Error: Wrong number of Args for the DELETE command"
  1145.                 WScript.Quit (GENERAL_FAILURE)
  1146.         End If
  1147.  
  1148.         ObjectPath = Args(1)
  1149.  
  1150.         ' Check and see if the user is specifically asking to delete the path
  1151.         DeletePathOnly = False
  1152.         If Right(ObjectPath, 1) = "/" Then
  1153.                 DeletePathOnly = True
  1154.         End If
  1155.  
  1156.         ' Sanitize the path and split parameter and path
  1157.         SanitizePath ObjectPath
  1158.         MachineName = SeparateMachineName(ObjectPath)
  1159.         ObjectParam = SplitParam(ObjectPath)
  1160.  
  1161.         ' Open the parent object
  1162.         IIsObjectPath = "IIS://" & MachineName
  1163.         If ObjectPath <> "" Then
  1164.                 IIsObjectPath = IIsObjectPath & "/" & ObjectPath
  1165.         End If
  1166.  
  1167.         Set IIsObject = GetObject(IIsObjectPath)
  1168.  
  1169.         If Err.Number <> 0 Then
  1170.                 WScript.Echo
  1171.                 ReportError ()
  1172.                 WScript.Echo "Error deleting the object: " & ObjectPath & "/" & ObjectParam
  1173.                 WScript.Quit (Err.Number)
  1174.         End If
  1175.  
  1176.         ' If they did not specifically ask to delete the path, then attempt to delete the property
  1177.         If Not DeletePathOnly Then
  1178.                 ' Try to delete the property
  1179.  
  1180.                 ' ADS_PROPERTY_CLEAR used to be defined, but it isn't anymore.
  1181.                 'IIsObject.PutEx ADS_PROPERTY_CLEAR, ObjectParam, DummyVariant
  1182.                 IIsObject.PutEx "1", ObjectParam, DummyVariant
  1183.  
  1184.                 ' If it succeeded, then just return, else continue and try to delete the path
  1185.                 If Err.Number = 0 Then
  1186.                         WScript.Echo "deleted property """ & ObjectParam & """"
  1187.                         Exit Function
  1188.                 End If
  1189.                 Err.Clear
  1190.         End If
  1191.  
  1192.         ' Try to just delete the path
  1193.         IIsObject.Delete "IIsObject", ObjectParam
  1194.  
  1195.         If Err.Number <> 0 Then
  1196.                 WScript.Echo
  1197.                 ReportError ()
  1198.                 WScript.Echo "Error deleting the object: " & ObjectPath & "/" & ObjectParam
  1199.                 WScript.Quit (Err.Number)
  1200.         End If
  1201.  
  1202.         WScript.Echo "deleted path """ & ObjectPath & "/" & ObjectParam & """"
  1203.  
  1204.         Exit Function
  1205.  
  1206. End Function
  1207.  
  1208.  
  1209. ''''''''''''''''''''''''''
  1210. '
  1211. ' EnumAllCommand
  1212. '
  1213. ' Enumerates all data and all properties in the metabase under the current path.
  1214. '
  1215. ''''''''''''''''''''''''''
  1216. Function EnumAllCommand()
  1217.         On Error Resume Next
  1218.  
  1219.         WScript.Echo "ENUM_ALL Command not yet supported"
  1220.         
  1221.  
  1222. End Function
  1223.  
  1224.  
  1225. ''''''''''''''''''''''''''
  1226. '
  1227. ' CopyMoveCommand
  1228. '
  1229. ' Copies a path in the metabase to another path.
  1230. '
  1231. ''''''''''''''''''''''''''
  1232. Function CopyMoveCommand(bCopyFlag)
  1233.         On Error Resume Next
  1234.  
  1235.         Dim SrcObjectPath
  1236.         Dim DestObjectPath
  1237.         Dim DestObject
  1238.  
  1239.         Dim ParentObjectPath
  1240.         Dim ParentRelativePath
  1241.         Dim ParentObject
  1242.  
  1243.         Dim MachineName
  1244.  
  1245.         Dim TmpDestLeftPath
  1246.         Dim TmpSrcLeftPath
  1247.  
  1248.         CopyMoveCommand = 0 ' Assume Success
  1249.  
  1250.         If ArgCount <> 3 Then
  1251.                 WScript.Echo "Error: Wrong number of Args for the Copy/Move command"
  1252.                 WScript.Quit (GENERAL_FAILURE)
  1253.         End If
  1254.  
  1255.         SrcObjectPath = Args(1)
  1256.         DestObjectPath = Args(2)
  1257.  
  1258.         SanitizePath SrcObjectPath
  1259.         SanitizePath DestObjectPath
  1260.         MachineName = SeparateMachineName(SrcObjectPath)
  1261.         ParentObjectPath = "IIS://" & MachineName
  1262.  
  1263.         ' Extract the left part of the paths until there are no more left parts to extract
  1264.         Do
  1265.                 TmpSrcLeftPath = SplitLeftPath(SrcObjectPath)
  1266.                 TmpDestLeftPath = SplitLeftPath(DestObjectPath)
  1267.  
  1268.                 If (SrcObjectPath = "") Or (DestObjectPath = "") Then
  1269.                         SrcObjectPath = TmpSrcLeftPath & "/" & SrcObjectPath
  1270.                         DestObjectPath = TmpDestLeftPath & "/" & DestObjectPath
  1271.                         Exit Do
  1272.                 End If
  1273.  
  1274.                 If (TmpSrcLeftPath <> TmpDestLeftPath) Then
  1275.                         SrcObjectPath = TmpSrcLeftPath & "/" & SrcObjectPath
  1276.                         DestObjectPath = TmpDestLeftPath & "/" & DestObjectPath
  1277.                         Exit Do
  1278.                 End If
  1279.  
  1280.                 ParentObjectPath = ParentObjectPath & "/" & TmpSrcLeftPath
  1281.                 ParentRelativePath = ParentRelativePath & "/" & TmpSrcLeftPath
  1282.  
  1283.         Loop
  1284.  
  1285.         SanitizePath SrcObjectPath
  1286.         SanitizePath DestObjectPath
  1287.         SanitizePath ParentObjectPath
  1288.  
  1289.         ' Now, open the parent object and Copy/Move the objects
  1290.         Set ParentObject = GetObject(ParentObjectPath)
  1291.  
  1292.         If (Err.Number <> 0) Then
  1293.                 ReportError ()
  1294.                 WScript.Echo "Error trying to open the object: " & ParentObjectPath
  1295.                 WScript.Quit (Err.Number)
  1296.         End If
  1297.  
  1298.         If (bCopyFlag) Then
  1299.                 Set DestObject = ParentObject.CopyHere(SrcObjectPath, DestObjectPath)
  1300.         Else
  1301.                 Set DestObject = ParentObject.MoveHere(SrcObjectPath, DestObjectPath)
  1302.         End If
  1303.  
  1304.         If (Err.Number <> 0) Then
  1305.                 ReportError ()
  1306.                 WScript.Echo "Error trying to Copy/Move Source to Dest."
  1307.                 WScript.Quit (Err.Number)
  1308.         End If
  1309.  
  1310.         If (bCopyFlag) Then
  1311.                 WScript.Echo "copied from " & ParentRelativePath & "/" & SrcObjectPath & " to " & ParentRelativePath & "/" & DestObjectPath
  1312.         Else
  1313.                 WScript.Echo "moved from " & ParentRelativePath & "/" & SrcObjectPath & " to " & ParentRelativePath & "/" & DestObjectPath
  1314.         End If
  1315.  
  1316. End Function
  1317.  
  1318. ''''''''''''''''''''''''''
  1319. '
  1320. ' StartServerCommand
  1321. '
  1322. ' Starts a server in the metabase.
  1323. '
  1324. ''''''''''''''''''''''''''
  1325. Function StartServerCommand()
  1326.  
  1327.         On Error Resume Next
  1328.  
  1329.         Dim IIsObject
  1330.         Dim IIsObjectPath
  1331.         Dim ObjectPath
  1332.         Dim MachineName
  1333.  
  1334.         If ArgCount <> 2 Then
  1335.                 WScript.Echo "Error: Wrong number of Args for the START_SERVER command"
  1336.                 WScript.Quit (GENERAL_FAILURE)
  1337.         End If
  1338.  
  1339.         ObjectPath = Args(1)
  1340.         SanitizePath ObjectPath
  1341.         MachineName = SeparateMachineName(ObjectPath)
  1342.         IIsObjectPath = "IIS://" & MachineName & "/" & ObjectPath
  1343.  
  1344.         Set IIsObject = GetObject(IIsObjectPath)
  1345.  
  1346.         If (Err.Number <> 0) Then
  1347.                 ReportError ()
  1348.                 WScript.Echo "Error trying to open the object: " & ObjectPath
  1349.                 WScript.Quit (Err.Number)
  1350.         End If
  1351. 'debug
  1352. 'WScript.echo "About to start server.  Last Error: " & Err.Number
  1353.         IIsObject.Start
  1354. 'WScript.echo "After starting server.  Last Error: " & Err.Number
  1355.         If (Err.Number <> 0) Then
  1356.                 ReportError ()
  1357.                 WScript.Echo "Error trying to START the server: " & ObjectPath
  1358.                 WScript.Quit (Err.Number)
  1359.         End If
  1360.         WScript.Echo "Server " & ObjectPath & " Successfully STARTED"
  1361.  
  1362. End Function
  1363.  
  1364. ''''''''''''''''''''''''''
  1365. '
  1366. ' StopServerCommand
  1367. '
  1368. ' Stops a server in the metabase.
  1369. '
  1370. ''''''''''''''''''''''''''
  1371. Function StopServerCommand()
  1372.  
  1373.         On Error Resume Next
  1374.  
  1375.         Dim IIsObject
  1376.         Dim IIsObjectPath
  1377.         Dim ObjectPath
  1378.         Dim MachineName
  1379.  
  1380.         If ArgCount <> 2 Then
  1381.                 WScript.Echo "Error: Wrong number of Args for the STOP_SERVER command"
  1382.                 WScript.Quit (GENERAL_FAILURE)
  1383.         End If
  1384.  
  1385.         ObjectPath = Args(1)
  1386.         SanitizePath ObjectPath
  1387.         MachineName = SeparateMachineName(ObjectPath)
  1388.         IIsObjectPath = "IIS://" & MachineName & "/" & ObjectPath
  1389.  
  1390.         Set IIsObject = GetObject(IIsObjectPath)
  1391.  
  1392.         If (Err.Number <> 0) Then
  1393.                 ReportError ()
  1394.                 WScript.Echo "Error trying to open the object: " & ObjectPath
  1395.                 WScript.Quit (Err.Number)
  1396.         End If
  1397.  
  1398.         IIsObject.Stop
  1399.         If (Err.Number <> 0) Then
  1400.                 ReportError ()
  1401.                 WScript.Echo "Error trying to STOP the server: " & ObjectPath
  1402.                 WScript.Quit (Err.Number)
  1403.         End If
  1404.         WScript.Echo "Server " & ObjectPath & " Successfully STOPPED"
  1405.  
  1406. End Function
  1407.  
  1408. ''''''''''''''''''''''''''
  1409. '
  1410. ' PauseServerCommand
  1411. '
  1412. ' Pauses a server in the metabase.
  1413. '
  1414. ''''''''''''''''''''''''''
  1415. Function PauseServerCommand()
  1416.  
  1417.         On Error Resume Next
  1418.  
  1419.         Dim IIsObject
  1420.         Dim IIsObjectPath
  1421.         Dim ObjectPath
  1422.         Dim MachineName
  1423.  
  1424.         If ArgCount <> 2 Then
  1425.                 WScript.Echo "Error: Wrong number of Args for the PAUSE_SERVER command"
  1426.                 WScript.Quit (GENERAL_FAILURE)
  1427.         End If
  1428.  
  1429.         ObjectPath = Args(1)
  1430.         SanitizePath ObjectPath
  1431.         MachineName = SeparateMachineName(ObjectPath)
  1432.         IIsObjectPath = "IIS://" & MachineName & "/" & ObjectPath
  1433.  
  1434.         Set IIsObject = GetObject(IIsObjectPath)
  1435.  
  1436.         If (Err.Number <> 0) Then
  1437.                 ReportError ()
  1438.                 WScript.Echo "Error trying to open the object: " & ObjectPath
  1439.                 WScript.Quit (Err.Number)
  1440.         End If
  1441.  
  1442.         IIsObject.Pause
  1443.         If (Err.Number <> 0) Then
  1444.                 ReportError ()
  1445.                 WScript.Echo "Error trying to PAUSE the server: " & ObjectPath
  1446.                 WScript.Quit (Err.Number)
  1447.         End If
  1448.         WScript.Echo "Server " & ObjectPath & " Successfully PAUSED"
  1449.  
  1450. End Function
  1451.  
  1452. ''''''''''''''''''''''''''
  1453. '
  1454. ' ContinueServerCommand
  1455. '
  1456. ' Continues a server in the metabase.
  1457. '
  1458. ''''''''''''''''''''''''''
  1459. Function ContinueServerCommand()
  1460.  
  1461.         On Error Resume Next
  1462.  
  1463.         Dim IIsObject
  1464.         Dim IIsObjectPath
  1465.         Dim ObjectPath
  1466.         Dim MachineName
  1467.  
  1468.         If ArgCount <> 2 Then
  1469.                 WScript.Echo "Error: Wrong number of Args for the CONTINUE_SERVER command"
  1470.                 WScript.Quit (GENERAL_FAILURE)
  1471.         End If
  1472.  
  1473.         ObjectPath = Args(1)
  1474.         SanitizePath ObjectPath
  1475.         MachineName = SeparateMachineName(ObjectPath)
  1476.         IIsObjectPath = "IIS://" & MachineName & "/" & ObjectPath
  1477.  
  1478.         Set IIsObject = GetObject(IIsObjectPath)
  1479.  
  1480.         If (Err.Number <> 0) Then
  1481.                 ReportError ()
  1482.                 WScript.Echo "Error trying to open the object: " & ObjectPath
  1483.                 WScript.Quit (Err.Number)
  1484.         End If
  1485.  
  1486.         IIsObject.Continue
  1487.         If (Err.Number <> 0) Then
  1488.                 ReportError ()
  1489.                 WScript.Echo "Error trying to CONTINUE the server: " & ObjectPath
  1490.                 WScript.Quit (Err.Number)
  1491.         End If
  1492.         WScript.Echo "Server " & ObjectPath & " Successfully CONTINUED"
  1493.  
  1494. End Function
  1495.  
  1496.  
  1497. Function FindData()
  1498.         ' FindData will accept 1 parameter from the command line - the node and
  1499.         ' property to search for (i.e. w3svc/1/ServerComment)
  1500.  
  1501.         On Error Resume Next
  1502.  
  1503.         Dim ObjectPath
  1504.         Dim ObjectParameter
  1505.         Dim NewObjectparameter
  1506.         Dim MachineName
  1507.  
  1508.         Dim IIsObjectPath
  1509.         Dim IIsObject
  1510.  
  1511.         Dim Path
  1512.         Dim PathList
  1513.         Dim I
  1514.  
  1515.         FindData = 0 ' Assume Success
  1516.  
  1517.         If ArgCount <> 2 Then
  1518.                 WScript.Echo "Error: Wrong number of Args for the FIND_DATA command"
  1519.                 WScript.Quit (GENERAL_FAILURE)
  1520.         End If
  1521.  
  1522.         ObjectPath = Args(1)
  1523.  
  1524.         SanitizePath ObjectPath
  1525.         MachineName = SeparateMachineName(ObjectPath)
  1526.         ObjectParameter = SplitParam(ObjectPath)
  1527.  
  1528.         ' Since people may still want to use MDUTIL parameter names
  1529.         ' we should still do the GET translation of parameter names.
  1530.         NewObjectparameter = MapSpecGetParamName(ObjectParameter)
  1531.         ObjectParameter = NewObjectparameter
  1532.  
  1533.         If ObjectPath = "" Then
  1534.                 IIsObjectPath = "IIS://" & MachineName
  1535.         Else
  1536.                 IIsObjectPath = "IIS://" & MachineName & "/" & ObjectPath
  1537.         End If
  1538.  
  1539.         Set IIsObject = GetObject(IIsObjectPath)
  1540.  
  1541.         If (Err.Number <> 0) Then
  1542.                 ReportError ()
  1543.                 WScript.Echo "Error trying to find data paths for the Object (GetObject Failed): " & ObjectPath
  1544.                 WScript.Quit (Err.Number)
  1545.         End If
  1546.  
  1547.         ' Now, list out all the places where this property exists.
  1548.         PathList = IIsObject.GetDataPaths(ObjectParameter, IIS_DATA_INHERIT)
  1549.         If Err.Number <> 0 Then PathList = IIsObject.GetDataPaths(ObjectParameter, IIS_DATA_NO_INHERIT)
  1550.  
  1551.         If (Err.Number <> 0) Then
  1552.                 ReportError ()
  1553.                 WScript.Echo "Error trying to get a path list (GetDataPaths Failed): " & ObjectPath
  1554.                 WScript.Quit (Err.Number)
  1555.         End If
  1556.  
  1557.         If UBound(PathList) < 0 Then
  1558.                 WScript.Echo "Property " & ObjectParameter & " was not found at any node beneath " & ObjectPath
  1559.         Else
  1560.                 WScript.Echo "Property " & ObjectParameter & " found at:"
  1561.  
  1562.                 For Each Path In PathList
  1563.                         Path = Right(Path, Len(Path) - 6)
  1564.                         Path = Right(Path, Len(Path) - InStr(Path, "/"))
  1565.                         WScript.Echo "  " & Path
  1566.                 Next
  1567.         End If
  1568.  
  1569.         If (Err.Number <> 0) Then
  1570.                 ReportError ()
  1571.                 WScript.Echo "Error listing the data paths (_newEnum Failed): " & ObjectPath
  1572.                 WScript.Quit (Err.Number)
  1573.         End If
  1574.  
  1575. End Function
  1576.  
  1577. '''''''''''''''''''''
  1578. '
  1579. ' MimeMapGet
  1580. '
  1581. ' Special function for displaying a MimeMap property
  1582. '
  1583. '''''''''''''''''''''
  1584. Function MimeMapGet(ObjectPath, MachineName)
  1585.         On Error Resume Next
  1586.  
  1587.         Dim MimePath
  1588.  
  1589.         Dim MimeMapList
  1590.         Dim MimeMapObject
  1591.         Dim MimeEntry
  1592.         Dim MimeEntryIndex
  1593.  
  1594.         Dim MimeStr
  1595.         Dim MimeOutPutStr
  1596.  
  1597.         Dim DataPathList
  1598.         Dim DataPath
  1599.  
  1600.         MimeMapGet = 0 ' Assume Success
  1601.  
  1602.         MimePath = "IIS://" & MachineName
  1603.         If ObjectPath <> "" Then MimePath = MimePath & "/" & ObjectPath
  1604.  
  1605.         ' Get the object that contains the mimemap
  1606.         Set MimeMapObject = GetObject(MimePath)
  1607.         If (Err.Number <> 0) Then
  1608.                 ReportError ()
  1609.                 WScript.Echo "Error trying to get the Object: " & ObjectPath
  1610.                 WScript.Quit (Err.Number)
  1611.         End If
  1612.  
  1613.         ' Test to see if the property is ACTUALLY set at this node
  1614.         DataPathList = MimeMapObject.GetDataPaths("MimeMap", IIS_DATA_INHERIT)
  1615.         If Err.Number <> 0 Then DataPathList = IIsObject.GetDataPaths(MimeMap, IIS_DATA_NO_INHERIT)
  1616.         Err.Clear
  1617.  
  1618.         ' If the data is not set anywhere, then stop the madness
  1619.         If (UBound(DataPathList) < 0) Then
  1620.                 MimeMapGet = &H80005006  ' end with property not set error
  1621.                 Exit Function
  1622.         End If
  1623.  
  1624.         DataPath = DataPathList(0)
  1625.         SanitizePath DataPath
  1626.  
  1627.         ' Test to see if the item is actually set HERE
  1628.         If UCase(DataPath) <> UCase(MimePath) Then
  1629.                 MimeMapGet = &H80005006  ' end with property not set error
  1630.                 Exit Function
  1631.         End If
  1632.  
  1633.         ' Get the mime map list from the object
  1634.         MimeMapList = MimeMapObject.Get("MimeMap")
  1635.         If (Err.Number <> 0) Then
  1636.                 ReportError ()
  1637.                 WScript.Echo "Error trying to get the Object: " & ObjectPath
  1638.                 WScript.Quit (Err.Number)
  1639.         End If
  1640.  
  1641.         MimeOutPutStr = "MimeMap                         : (MimeMapList) "
  1642.  
  1643.         ' Enumerate the Mime Entries
  1644.         For MimeEntryIndex = 0 To UBound(MimeMapList)
  1645.                 Set MimeEntry = MimeMapList(MimeEntryIndex)
  1646.                 MimeOutPutStr = MimeOutPutStr & """" & MimeEntry.Extension & "," & MimeEntry.MimeType & """ "
  1647.         Next
  1648.  
  1649.         If (Err.Number <> 0) Then
  1650.                 ReportError ()
  1651.                 WScript.Echo "Error trying to Create the Mime Map List."
  1652.                 WScript.Quit (Err.Number)
  1653.         End If
  1654.  
  1655.         WScript.Echo MimeOutPutStr
  1656.  
  1657. End Function
  1658.  
  1659.  
  1660.  
  1661. Function MimeMapSet(ObjectPath, ObjectParameter, MachineName)
  1662.         On Error Resume Next
  1663.  
  1664.         Dim MimePath
  1665.  
  1666.         Dim MimeEntryIndex
  1667.         Dim MimeMapList()
  1668.         Dim MimeMapObject
  1669.         Dim MimeEntry
  1670.  
  1671.         Dim MimeStr
  1672.         Dim MimeOutPutStr
  1673.  
  1674.         MimeMapSet = 0 ' Assume Success
  1675.  
  1676.         ' First, check the number of args
  1677.         If ArgCount < 3 Then
  1678.                 WScript.Echo "Error: Wrong number of Args for the Set MIMEMAP command"
  1679.                 WScript.Quit (GENERAL_FAILURE)
  1680.         End If
  1681.  
  1682.  
  1683.         MimePath = "IIS://" & MachineName
  1684.         If ObjectPath <> "" Then MimePath = MimePath & "/" & ObjectPath
  1685.  
  1686.         ' Get the object that contains the mimemap
  1687.         Set MimeMapObject = GetObject(MimePath)
  1688.         If (Err.Number <> 0) Then
  1689.                 ReportError ()
  1690.                 WScript.Echo "Error trying to get the Object: " & ObjectPath
  1691.                 WScript.Quit (Err.Number)
  1692.         End If
  1693.  
  1694.         ' Create a new MimeMapList of Mime Entries
  1695.         ReDim MimeMapList(ArgCount - 3)
  1696.  
  1697.         MimeOutPutStr = "MimeMap                         : (MimeMapList) "
  1698.  
  1699.         ' Fill the list with mime entries
  1700.         For MimeEntryIndex = 0 To UBound(MimeMapList)
  1701.  
  1702.                 MimeStr = Args(2 + MimeEntryIndex)
  1703.                 MimeOutPutStr = MimeOutPutStr & """" & MimeStr & """ "
  1704.  
  1705.                 Set MimeEntry = CreateObject("MimeMap")
  1706.  
  1707.                 MimeEntry.MimeType = Right(MimeStr, InStr(MimeStr, ",") - 1)
  1708.                 MimeEntry.Extension = Left(MimeStr, InStr(MimeStr, ",") - 1)
  1709.  
  1710.                 Set MimeMapList(MimeEntryIndex) = MimeEntry
  1711.         Next
  1712.  
  1713.         If (Err.Number <> 0) Then
  1714.                 ReportError ()
  1715.                 WScript.Echo "Error trying to Create the Mime Map List."
  1716.                 WScript.Quit (Err.Number)
  1717.         End If
  1718.  
  1719.         MimeMapObject.MimeMap = MimeMapList
  1720.         MimeMapObject.Setinfo
  1721.  
  1722.         If (Err.Number <> 0) Then
  1723.                 ReportError ()
  1724.                 WScript.Echo "Error Trying to set the Object's ""MimeMap"" property to the new mimemap list."
  1725.                 WScript.Quit (Err.Number)
  1726.         End If
  1727.  
  1728.         WScript.Echo MimeOutPutStr
  1729.  
  1730. End Function
  1731.  
  1732. ''''''''''''''''''''''''''
  1733. '
  1734. ' IsSpecialGetProperty
  1735. '
  1736. ' Checks to see if the property requires special processing in order to
  1737. ' display its contents.
  1738. '
  1739. ''''''''''''''''''''''''''
  1740. Function IsSpecialGetProperty(ObjectParameter)
  1741.  
  1742.         On Error Resume Next
  1743.  
  1744.         Select Case UCase(ObjectParameter)
  1745.                 Case "MIMEMAP"
  1746.                         IsSpecialGetProperty = True
  1747.                 Case Else
  1748.                         IsSpecialGetProperty = False
  1749.         End Select
  1750.  
  1751. End Function
  1752.  
  1753. ''''''''''''''''''''''''''
  1754. '
  1755. ' DoSpecialGetProp
  1756. '
  1757. ' Checks to see if the property requires special processing in order to
  1758. ' display its contents.
  1759. '
  1760. ''''''''''''''''''''''''''
  1761. Function DoSpecialGetProp(ObjectPath, ObjectParameter, MachineName)
  1762.  
  1763.         On Error Resume Next
  1764.  
  1765.         Select Case UCase(ObjectParameter)
  1766.                 Case "MIMEMAP"
  1767.                         DoSpecialGetProp = MimeMapGet(ObjectPath, MachineName)
  1768.                 Case Else
  1769.                         DoSpecialGetProp = False
  1770.         End Select
  1771.  
  1772. End Function
  1773.  
  1774.  
  1775.  
  1776. ''''''''''''''''''''''''''
  1777. '
  1778. ' IsSpecialSetProperty
  1779. '
  1780. ' Checks to see if the property is a type that needs to be handled
  1781. ' specially for compatibility with mdutil
  1782. '
  1783. ''''''''''''''''''''''''''
  1784. Function IsSpecialSetProperty(ObjectParameter)
  1785.  
  1786.         On Error Resume Next
  1787.  
  1788.         Select Case UCase(ObjectParameter)
  1789.                 Case "SERVERCOMMAND"
  1790.                         IsSpecialSetProperty = True
  1791.                 Case "ACCESSPERM"
  1792.                         IsSpecialSetProperty = True
  1793.                 Case "VRPATH"
  1794.                         IsSpecialSetProperty = True
  1795.                 Case "AUTHORIZATION"
  1796.                         IsSpecialSetProperty = True
  1797.                 Case "MIMEMAP"
  1798.                         IsSpecialSetProperty = True
  1799.                 Case Else
  1800.                         IsSpecialSetProperty = False
  1801.         End Select
  1802. End Function
  1803.  
  1804. ''''''''''''''''''''''''''
  1805. '
  1806. ' DoSpecialSetProp
  1807. '
  1808. ' Handles datatypes that need to be handled
  1809. ' specially for compatibility with mdutil
  1810. '
  1811. ''''''''''''''''''''''''''
  1812. Function DoSpecialSetProp(ObjectPath, ObjectParameter, MachineName)
  1813.         Dim IIsObjectPath
  1814.         Dim IIsObject
  1815.         Dim ValueList
  1816.         Dim ValueDisplay
  1817.         Dim PermIndex
  1818.  
  1819.         On Error Resume Next
  1820.  
  1821.         DoSpecialSetProp = 0 ' Assume Success
  1822.         Select Case UCase(ObjectParameter)
  1823.                 Case "SERVERCOMMAND"
  1824.  
  1825.                         IIsObjectPath = "IIS://" & MachineName & "/" & ObjectPath
  1826.                         Set IIsObject = GetObject(IIsObjectPath)
  1827.  
  1828.                         If (Err.Number <> 0) Then
  1829.                                 ReportError ()
  1830.                                 WScript.Echo "Error Trying To Get the Object: " & ObjectPath
  1831.                                 WScript.Quit (Err.Number)
  1832.                         End If
  1833.  
  1834.                         ValueList = CLng(Args(2))
  1835.                         Select Case ValueList
  1836.                                 Case 1
  1837.                                         IIsObject.Start
  1838.                                         If (Err.Number <> 0) Then
  1839.                                                 ReportError ()
  1840.                                                 WScript.Echo "Error Trying To Start the server: " & ObjectPath
  1841.                                                 WScript.Quit (Err.Number)
  1842.                                         End If
  1843.                                         WScript.Echo "Server " & ObjectPath & " Successfully STARTED"
  1844.                                 Case 2
  1845.                                         IIsObject.Stop
  1846.                                         If (Err.Number <> 0) Then
  1847.                                                 ReportError ()
  1848.                                                 WScript.Echo "Error Trying To Stop the server: " & ObjectPath
  1849.                                                 WScript.Quit (Err.Number)
  1850.                                         End If
  1851.                                         WScript.Echo "Server " & ObjectPath & " Successfully STOPPED"
  1852.                                 Case 3
  1853.                                         IIsObject.Pause
  1854.                                         If (Err.Number <> 0) Then
  1855.                                                 ReportError ()
  1856.                                                 WScript.Echo "Error Trying To Pause the server: " & ObjectPath
  1857.                                                 WScript.Quit (Err.Number)
  1858.                                         End If
  1859.                                         WScript.Echo "Server " & ObjectPath & " Successfully PAUSED"
  1860.                                 Case 4
  1861.                                         IIsObject.Continue
  1862.                                         If (Err.Number <> 0) Then
  1863.                                                 ReportError ()
  1864.                                                 WScript.Echo "Error Trying To Continue the server: " & ObjectPath
  1865.                                                 WScript.Quit (Err.Number)
  1866.                                         End If
  1867.                                         WScript.Echo "Server " & ObjectPath & " Successfully Continued"
  1868.                                 Case Else
  1869.                                         WScript.Echo "Invalid ServerCommand: " & ValueList
  1870.                                         DoSpecialSetProp = GENERAL_FAILURE
  1871.                         End Select
  1872.                         Exit Function
  1873.  
  1874.                 Case "ACCESSPERM"
  1875.                         IIsObjectPath = "IIS://" & MachineName & "/" & ObjectPath
  1876.                         Set IIsObject = GetObject(IIsObjectPath)
  1877.  
  1878.                         If (Err.Number <> 0) Then
  1879.                                 ReportError ()
  1880.                                 WScript.Echo "Error Trying To Get the Object: " & ObjectPath
  1881.                                 WScript.Quit (Err.Number)
  1882.                         End If
  1883.  
  1884.                         ' Set the access flags to None, first, and then add them back, as necessary
  1885.                         IIsObject.AccessFlags = 0
  1886.  
  1887.                         ' Set up the display output
  1888.                         ValueDisplay = "AccessFlags (AccessPerm)" & (Right(Spacer, SpacerSize - Len("AccessFlags (AccessPerm)")) & ": " & "(" & TypeName(IIsObject.AccessFlags) & ") ")
  1889.  
  1890.                         ' Attempt to convert parameter to number
  1891.                         Dim APValue
  1892.                         Dim TempValStr
  1893.  
  1894.                         TempValStr = Args(2)
  1895.  
  1896.                         ' Check for Hex
  1897.                         If (UCase(Left(Args(2), 2)) = "0X") Then
  1898.                                 TempValStr = "&H" & Right(TempValStr, Len(TempValStr) - 2)
  1899.                         End If
  1900.  
  1901.                         APValue = CLng(TempValStr)
  1902.  
  1903.                         If (Err.Number = 0) Then
  1904.                                 IIsObject.AccessFlags = APValue
  1905.                                 ValueDisplay = ValueDisplay & " " & APValue & " (0x" & Hex(APValue) & ")"
  1906.                         Else
  1907.                                 Err.Clear
  1908.                                 For PermIndex = 2 To ArgCount - 1
  1909.                                         Select Case UCase(Args(PermIndex))
  1910.                                                 Case "READ"
  1911.                                                         IIsObject.AccessRead = True
  1912.                                                         ValueDisplay = ValueDisplay & " Read"
  1913.                                                 Case "WRITE"
  1914.                                                         IIsObject.AccessWrite = True
  1915.                                                         ValueDisplay = ValueDisplay & " Write"
  1916.                                                 Case "EXECUTE"
  1917.                                                         IIsObject.AccessExecute = True
  1918.                                                         ValueDisplay = ValueDisplay & " Execute"
  1919.                                                 Case "SCRIPT"
  1920.                                                         IIsObject.AccessScript = True
  1921.                                                         ValueDisplay = ValueDisplay & " Script"
  1922.                                                 Case Else
  1923.                                                         WScript.Echo "Error: Setting not supported: " & Args(PermIndex)
  1924.                                                         WScript.Quit (GENERAL_FAILURE)
  1925.                                         End Select
  1926.                                 Next
  1927.                         End If
  1928.  
  1929.                         If (Err.Number <> 0) Then
  1930.                                 ReportError ()
  1931.                                 WScript.Echo "Error Trying To Set data on the Object: " & ObjectPath
  1932.                                 WScript.Quit (Err.Number)
  1933.                         End If
  1934.  
  1935.                         IIsObject.Setinfo
  1936.  
  1937.                         If (Err.Number <> 0) Then
  1938.                                 ReportError ()
  1939.                                 WScript.Echo "Error Trying To Set data on the Object: " & ObjectPath
  1940.                                 WScript.Quit (Err.Number)
  1941.                         End If
  1942.  
  1943.                         ' Send the current settings to the screen
  1944.                         WScript.Echo ValueDisplay
  1945.  
  1946.                 Case "VRPATH"
  1947.                         IIsObjectPath = "IIS://" & MachineName & "/" & ObjectPath
  1948.                         Set IIsObject = GetObject(IIsObjectPath)
  1949.  
  1950.                         If (Err.Number <> 0) Then
  1951.                                 ReportError ()
  1952.                                 WScript.Echo "Error Trying To Get the Object: " & ObjectPath
  1953.                                 WScript.Quit (Err.Number)
  1954.                         End If
  1955.  
  1956.                         ' Set the access flags to None, first, and then add them back, as necessary
  1957.                         IIsObject.Path = Args(2)
  1958.  
  1959.                         If (Err.Number <> 0) Then
  1960.                                 ReportError ()
  1961.                                 WScript.Echo "Error Trying To Set data on the Object: " & ObjectPath
  1962.                                 WScript.Quit (Err.Number)
  1963.                         End If
  1964.  
  1965.                         ' Set up the display output
  1966.                         ValueDisplay = "Path (VRPath)" & (Right(Spacer, SpacerSize - Len("Path (VRPath)")) & ": " & "(" & TypeName(IIsObject.Path) & ") " & IIsObject.Path)
  1967.  
  1968.                         IIsObject.Setinfo
  1969.  
  1970.                         If (Err.Number <> 0) Then
  1971.                                 ReportError ()
  1972.                                 WScript.Echo "Error Trying To Set data on the Object: " & ObjectPath
  1973.                                 WScript.Quit (Err.Number)
  1974.                         End If
  1975.  
  1976.                         ' Send the current settings to the screen
  1977.                         WScript.Echo ValueDisplay
  1978.  
  1979.                 Case "AUTHORIZATION"
  1980.                         IIsObjectPath = "IIS://" & MachineName & "/" & ObjectPath
  1981.                         Set IIsObject = GetObject(IIsObjectPath)
  1982.  
  1983.                         If (Err.Number <> 0) Then
  1984.                                 ReportError ()
  1985.                                 WScript.Echo "Error Trying To Get the Object: " & ObjectPath
  1986.                                 WScript.Quit (Err.Number)
  1987.                         End If
  1988.  
  1989.                         ' Set the auth flags to None, first, and then add them back, as necessary
  1990.                         IIsObject.AuthFlags = 0
  1991.  
  1992.                         ' Set up the display output
  1993.                         ValueDisplay = "Authorization" & (Right(Spacer, SpacerSize - Len("Authorization")) & ": " & "(" & TypeName(IIsObject.AuthFlags) & ") ")
  1994.  
  1995.                         For PermIndex = 2 To ArgCount - 1
  1996.                                 Select Case UCase(Args(PermIndex))
  1997.                                         Case "NT"
  1998.                                                 IIsObject.AuthNTLM = True
  1999.                                                 ValueDisplay = ValueDisplay & " NT"
  2000.                                         Case "ANONYMOUS"
  2001.                                                 IIsObject.AuthAnonymous = True
  2002.                                                 ValueDisplay = ValueDisplay & " Anonymous"
  2003.                                         Case "BASIC"
  2004.                                                 IIsObject.AuthBasic = True
  2005.                                                 ValueDisplay = ValueDisplay & " Basic"
  2006.                                         Case Else
  2007.                                                 WScript.Echo "Error: Setting not supported: " & Args(PermIndex)
  2008.                                                 WScript.Quit (GENERAL_FAILURE)
  2009.                                 End Select
  2010.                         Next
  2011.  
  2012.                         If (Err.Number <> 0) Then
  2013.                                 ReportError ()
  2014.                                 WScript.Echo "Error Trying To Set data on the Object: " & ObjectPath
  2015.                                 WScript.Quit (Err.Number)
  2016.                         End If
  2017.  
  2018.                         IIsObject.Setinfo
  2019.  
  2020.                         If (Err.Number <> 0) Then
  2021.                                 ReportError ()
  2022.                                 WScript.Echo "Error Trying To Set data on the Object: " & ObjectPath
  2023.                                 WScript.Quit (Err.Number)
  2024.                         End If
  2025.  
  2026.                         ' Send the current settings to the screen
  2027.                         WScript.Echo ValueDisplay
  2028.  
  2029.                 Case "MIMEMAP"
  2030.                         DoSpecialSetProp = MimeMapSet(ObjectPath, ObjectParameter, MachineName)
  2031. '               Case "FILTER"
  2032. '                       DoSpecialSetProp = FiltersSet()
  2033.                 Case Else
  2034.                         DoSpecialSetProp = GENERAL_FAILURE
  2035.         End Select
  2036. End Function
  2037.  
  2038. ''''''''''''''''''''''''''''''
  2039. '
  2040. ' Function SeparateMachineName
  2041. '
  2042. ' This function will get the machine name from the Path parameter
  2043. ' that was passed into the script.  It will also alter the passed in
  2044. ' path so that it contains only the rest of the path - not the machine
  2045. ' name.  If there is no machine name in the path, then the script
  2046. ' will assume LocalHost.
  2047. '
  2048. ''''''''''''''''''''''''''''''
  2049. Function SeparateMachineName(Path)
  2050.         On Error Resume Next
  2051.  
  2052.         ' Temporarily, just return LocalHost
  2053.         ' SeparateMachineName = "LocalHost"
  2054.  
  2055.         SeparateMachineName = TargetServer
  2056.  
  2057.         Exit Function
  2058. End Function
  2059.  
  2060. ''''''''''''''''''''''''''''''
  2061. '
  2062. ' Function MapSpecGetParamName
  2063. '
  2064. ' Some parameters in MDUTIL are named differently in ADSI.
  2065. ' This function maps the improtant parameter names to ADSI
  2066. ' names.
  2067. '
  2068. ''''''''''''''''''''''''''''''
  2069. Function MapSpecGetParamName(ObjectParameter)
  2070.         On Error Resume Next
  2071.  
  2072.         Select Case UCase(ObjectParameter)
  2073.                 Case "ACCESSPERM"
  2074.                         WScript.Echo "Note: Your parameter """ & ObjectParameter & """ is being mapped to AccessFlags"
  2075.                         WScript.Echo "      Check individual perms using ""GET AccessRead"", ""GET AccessWrite"", etc."
  2076.                         MapSpecGetParamName = "AccessFlags"
  2077.                 Case "VRPATH"
  2078.                         'WScript.Echo "Note: Your parameter """ & ObjectParameter & """ is being mapped to PATH"
  2079.                         MapSpecGetParamName = "Path"
  2080.                 Case "AUTHORIZATION"
  2081.                         WScript.Echo "Note: Your parameter """ & ObjectParameter & """ is being mapped to AuthFlags"
  2082.                         WScript.Echo "      Check individual auths using ""GET AuthNTLM"", ""GET AuthBasic"", etc."
  2083.                         MapSpecGetParamName = "AuthFlags"
  2084.                 Case Else
  2085.                         ' Do nothing - the parameter doesn't map to anything special
  2086.                         MapSpecGetParamName = ObjectParameter
  2087.         End Select
  2088. End Function
  2089.  
  2090. Sub ReportError()
  2091. '       On Error Resume Next
  2092.  
  2093.         Dim ErrorDescription
  2094.  
  2095.         Select Case (Err.Number)
  2096.                 Case &H80070003
  2097.                         ErrorDescription = "The path requested could not be found."
  2098.                 Case &H80070005
  2099.                         ErrorDescription = "Access is denied for the requested path or property."
  2100.                 Case &H80070094
  2101.                         ErrorDescription = "The requested path is being used by another application."
  2102.                 Case Else
  2103.                         ErrorDescription = Err.Description
  2104.         End Select
  2105.  
  2106.         WScript.Echo ErrorDescription
  2107.         WScript.Echo "ErrNumber: " & Err.Number & " (0x" & Hex(Err.Number) & ")"
  2108. End Sub
  2109.  
  2110.  
  2111.  
  2112.  
  2113. Function SplitParam(ObjectPath)
  2114. ' Note: Assume the string has been sanitized (no leading or trailing slashes)
  2115.         On Error Resume Next
  2116.  
  2117.         Dim SlashIndex
  2118.         Dim TempParam
  2119.         Dim ObjectPathLen
  2120.  
  2121.         SplitParam = ""  ' Assume no parameter
  2122.         ObjectPathLen = Len(ObjectPath)
  2123.  
  2124.         ' Separate the path of the node from the parameter
  2125.         SlashIndex = InStrRev(ObjectPath, "/")
  2126.  
  2127.         If (SlashIndex = 0) Or (SlashIndex = ObjectPathLen) Then
  2128.                 TempParam = ObjectPath
  2129.                 ObjectPath = "" ' ObjectParameter is more important
  2130.         Else
  2131.                 TempParam = ObjectPath
  2132.                 ObjectPath = Left(ObjectPath, SlashIndex - 1)
  2133.                 TempParam = Right(TempParam, Len(TempParam) - SlashIndex)
  2134.         End If
  2135.  
  2136.         SplitParam = TempParam
  2137.  
  2138.         If (Err.Number <> 0) Then
  2139.                 ReportError ()
  2140.                 WScript.Echo "Error trying to Split the parameter from the object: " & ObjectPath
  2141.                 WScript.Quit (Err.Number)
  2142.         End If
  2143.  
  2144. End Function
  2145.  
  2146.  
  2147.  
  2148. Function SplitLeftPath(ObjectPath)
  2149. ' Note: Assume the string has been sanitized (no leading or trailing slashes)
  2150.         On Error Resume Next
  2151.  
  2152.         Dim SlashIndex
  2153.         Dim TmpLeftPath
  2154.         Dim ObjectPathLen
  2155.  
  2156. 'WScript.Echo "SplitLeftPath: ObjectPath: " & ObjectPath
  2157. 'WScript.Echo "LastError: " & Err.Number & " (" & Hex (Err.Number) & ")"
  2158.  
  2159.         SplitLeftPath = ""  ' Assume no LeftPath
  2160.         ObjectPathLen = Len(ObjectPath)
  2161.  
  2162.         ' Separate the left part of the path from the remaining path
  2163.         SlashIndex = InStr(ObjectPath, "/")
  2164.  
  2165.         If (SlashIndex = 0) Or (SlashIndex = ObjectPathLen) Then
  2166.                 TmpLeftPath = ObjectPath
  2167.                 ObjectPath = ""
  2168.         Else
  2169.                 TmpLeftPath = Left(ObjectPath, SlashIndex - 1)
  2170.                 ObjectPath = Right(ObjectPath, Len(ObjectPath) - SlashIndex)
  2171.         End If
  2172.  
  2173. 'WScript.Echo "SplitLeftPath: ObjectPath: " & ObjectPath
  2174. 'WScript.Echo "SplitLeftPath: TmpLeftPath: " & TmpLeftPath
  2175. 'WScript.Echo "LastError: " & Err.Number & " (" & Hex (Err.Number) & ")"
  2176.  
  2177.         SplitLeftPath = TmpLeftPath
  2178.  
  2179. 'WScript.Echo "SplitLeftPath: ObjectPath: " & ObjectPath
  2180. 'WScript.Echo "LastError: " & Err.Number & " (" & Hex (Err.Number) & ")"
  2181. 'WScript.Echo "SplitLeftPath: TmpLeftPath: " & TmpLeftPath
  2182.  
  2183.         If (Err.Number <> 0) Then
  2184.                 ReportError ()
  2185.                 WScript.Echo "Error trying to split the left part of the path: " & ObjectPath
  2186.                 WScript.Quit (Err.Number)
  2187.         End If
  2188.  
  2189. End Function
  2190.  
  2191.  
  2192.  
  2193.  
  2194. Sub SanitizePath(ObjectPath)
  2195.         On Error Resume Next
  2196.  
  2197.         ' Remove WhiteSpace
  2198.         Do While (Left(ObjectPath, 1) = " ")
  2199.                 ObjectPath = Right(ObjectPath, Len(ObjectPath) - 1)
  2200.         Loop
  2201.  
  2202.         Do While (Right(ObjectPath, 1) = " ")
  2203.                 ObjectPath = Left(ObjectPath, Len(ObjectPath) - 1)
  2204.         Loop
  2205.  
  2206.         ' Replace all occurrences of \ with /
  2207.         ObjectPath = Replace(ObjectPath, "\", "/")
  2208.  
  2209.         ' Remove leading and trailing slashes
  2210.         If Left(ObjectPath, 1) = "/" Then
  2211.                 ObjectPath = Right(ObjectPath, Len(ObjectPath) - 1)
  2212.         End If
  2213.  
  2214.         If Right(ObjectPath, 1) = "/" Then
  2215.                 ObjectPath = Left(ObjectPath, Len(ObjectPath) - 1)
  2216.         End If
  2217.  
  2218.         If (Err.Number <> 0) Then
  2219.                 ReportError ()
  2220.                 WScript.Echo "Error Trying To Sanitize the path: " & ObjectPath
  2221.                 WScript.Quit (Err.Number)
  2222.         End If
  2223.  
  2224. End Sub
  2225.  
  2226.  
  2227. '''''''''''''''''''''''''''''
  2228. ' AppCreateCommand
  2229. '''''''''''''''''''''''''''''
  2230. Function AppCreateCommand(InProcFlag)
  2231.         On Error Resume Next
  2232.  
  2233.         Dim IIsObject
  2234.         Dim IIsObjectPath
  2235.         Dim ObjectPath
  2236.         Dim MachineName
  2237.  
  2238.         AppCreateCommand = 0 ' Assume Success
  2239.  
  2240.         If ArgCount <> 2 Then
  2241.                 WScript.Echo "Error: Wrong number of Args for the APPCREATE command"
  2242.                 WScript.Quit (GENERAL_FAILURE)
  2243.         End If
  2244.  
  2245.         ObjectPath = Args(1)
  2246.         SanitizePath ObjectPath
  2247.         MachineName = SeparateMachineName(ObjectPath)
  2248.  
  2249.         IIsObjectPath = "IIS://" & MachineName
  2250.         If ObjectPath <> "" Then
  2251.                 IIsObjectPath = IIsObjectPath & "/" & ObjectPath
  2252.         End If
  2253.  
  2254.         Set IIsObject = GetObject(IIsObjectPath)
  2255.  
  2256.         If (Err.Number <> 0) Then
  2257.                 ReportError ()
  2258.                 WScript.Echo "Error trying to get the path of the application: " & ObjectPath
  2259.                 WScript.Quit (Err.Number)
  2260.         End If
  2261.  
  2262.         IIsObject.AppCreate2 (InProcFlag)
  2263.  
  2264.         If (Err.Number <> 0) Then
  2265.                 ReportError ()
  2266.                 WScript.Echo "Error trying to create the application: " & ObjectPath
  2267.                 WScript.Quit (Err.Number)
  2268.         End If
  2269.  
  2270.         WScript.Echo "Application Created."
  2271.  
  2272. End Function
  2273.  
  2274.  
  2275. '''''''''''''''''''''''''''''
  2276. ' AppDeleteCommand
  2277. '''''''''''''''''''''''''''''
  2278. Function AppDeleteCommand()
  2279.         On Error Resume Next
  2280.  
  2281.         Dim IIsObject
  2282.         Dim IIsObjectPath
  2283.         Dim ObjectPath
  2284.         Dim MachineName
  2285.  
  2286.         AppDeleteCommand = 0 ' Assume Success
  2287.  
  2288.         If ArgCount <> 2 Then
  2289.                 WScript.Echo "Error: Wrong number of Args for the APPDELETE command"
  2290.                 WScript.Quit (GENERAL_FAILURE)
  2291.         End If
  2292.  
  2293.         ObjectPath = Args(1)
  2294.         SanitizePath ObjectPath
  2295.         MachineName = SeparateMachineName(ObjectPath)
  2296.  
  2297.         IIsObjectPath = "IIS://" & MachineName
  2298.         If ObjectPath <> "" Then
  2299.                 IIsObjectPath = IIsObjectPath & "/" & ObjectPath
  2300.         End If
  2301.  
  2302.         Set IIsObject = GetObject(IIsObjectPath)
  2303.  
  2304.         If (Err.Number <> 0) Then
  2305.                 ReportError ()
  2306.                 WScript.Echo "Error trying to get the path of the application: " & ObjectPath
  2307.                 WScript.Quit (Err.Number)
  2308.         End If
  2309.  
  2310.         IIsObject.AppDelete
  2311.  
  2312.         If (Err.Number <> 0) Then
  2313.                 ReportError ()
  2314.                 WScript.Echo "Error trying to DELETE the application: " & ObjectPath
  2315.                 WScript.Quit (Err.Number)
  2316.         End If
  2317.  
  2318.         WScript.Echo "Application Deleted."
  2319.  
  2320. End Function
  2321.  
  2322.  
  2323. '''''''''''''''''''''''''''''
  2324. ' AppUnloadCommand
  2325. '''''''''''''''''''''''''''''
  2326. Function AppUnloadCommand()
  2327.         On Error Resume Next
  2328.  
  2329.         Dim IIsObject
  2330.         Dim IIsObjectPath
  2331.         Dim ObjectPath
  2332.         Dim MachineName
  2333.  
  2334.         AppUnloadCommand = 0 ' Assume Success
  2335.  
  2336.         If ArgCount <> 2 Then
  2337.                 WScript.Echo "Error: Wrong number of Args for the APPUNLOAD command"
  2338.                 WScript.Quit (GENERAL_FAILURE)
  2339.         End If
  2340.  
  2341.         ObjectPath = Args(1)
  2342.         SanitizePath ObjectPath
  2343.         MachineName = SeparateMachineName(ObjectPath)
  2344.  
  2345.         IIsObjectPath = "IIS://" & MachineName
  2346.         If ObjectPath <> "" Then
  2347.                 IIsObjectPath = IIsObjectPath & "/" & ObjectPath
  2348.         End If
  2349.  
  2350.         Set IIsObject = GetObject(IIsObjectPath)
  2351.  
  2352.         If (Err.Number <> 0) Then
  2353.                 ReportError ()
  2354.                 WScript.Echo "Error trying to get the path of the application: " & ObjectPath
  2355.                 WScript.Quit (Err.Number)
  2356.         End If
  2357.  
  2358.         IIsObject.AppUnload
  2359.  
  2360.         If (Err.Number <> 0) Then
  2361.                 ReportError ()
  2362.                 WScript.Echo "Error trying to UNLOAD the application: " & ObjectPath
  2363.                 WScript.Quit (Err.Number)
  2364.         End If
  2365.  
  2366.         WScript.Echo "Application Unloaded."
  2367.  
  2368. End Function
  2369.  
  2370.  
  2371. Function AppDisableCommand()
  2372.         On Error Resume Next
  2373.  
  2374.         Dim IIsObject
  2375.         Dim IIsObjectPath
  2376.         Dim ObjectPath
  2377.         Dim MachineName
  2378.  
  2379.         AppDisableCommand = 0 ' Assume Success
  2380.  
  2381.         If ArgCount <> 2 Then
  2382.                 WScript.Echo "Error: Wrong number of Args for the APPDISABLE command"
  2383.                 WScript.Quit (GENERAL_FAILURE)
  2384.         End If
  2385.  
  2386.         ObjectPath = Args(1)
  2387.         SanitizePath ObjectPath
  2388.         MachineName = SeparateMachineName(ObjectPath)
  2389.  
  2390. 'debug
  2391. 'WScript.Echo "Last Error: " & Err & " (" & Hex (Err) & "): " & Err.Description
  2392.  
  2393.         IIsObjectPath = "IIS://" & MachineName
  2394.         If ObjectPath <> "" Then
  2395.             IIsObjectPath = IIsObjectPath & "/" & ObjectPath
  2396.         End If
  2397.  
  2398.         Set IIsObject = GetObject(IIsObjectPath)
  2399.  
  2400.         If (Err.Number <> 0) Then
  2401.                 ReportError ()
  2402.                 WScript.Echo "Error trying to get the path of the application: " & ObjectPath
  2403.                 WScript.Quit (Err.Number)
  2404.         End If
  2405.  
  2406.         IIsObject.AppDisable
  2407.  
  2408.         If (Err.Number <> 0) Then
  2409.                 ReportError ()
  2410.                 WScript.Echo "Error trying to disable the application: " & ObjectPath
  2411.                 WScript.Quit (Err.Number)
  2412.         End If
  2413.  
  2414. 'debug
  2415. 'WScript.Echo "Last Error: " & Err & " (" & Hex (Err) & "): " & Err.Description
  2416.  
  2417.         WScript.Echo "Application Disabled."
  2418.  
  2419. End Function
  2420.  
  2421. Function AppEnableCommand()
  2422.         On Error Resume Next
  2423.  
  2424.         Dim IIsObject
  2425.         Dim IIsObjectPath
  2426.         Dim ObjectPath
  2427.         Dim MachineName
  2428.  
  2429.         AppEnableCommand = 0 ' Assume Success
  2430.  
  2431.         If ArgCount <> 2 Then
  2432.                 WScript.Echo "Error: Wrong number of Args for the APPENABLE command"
  2433.                 WScript.Quit (GENERAL_FAILURE)
  2434.         End If
  2435.  
  2436.         ObjectPath = Args(1)
  2437.         SanitizePath ObjectPath
  2438.         MachineName = SeparateMachineName(ObjectPath)
  2439.  
  2440. 'debug
  2441. 'WScript.Echo "Last Error: " & Err & " (" & Hex (Err) & "): " & Err.Description
  2442.  
  2443.         IIsObjectPath = "IIS://" & MachineName
  2444.         If ObjectPath <> "" Then
  2445.             IIsObjectPath = IIsObjectPath & "/" & ObjectPath
  2446.         End If
  2447.  
  2448.         Set IIsObject = GetObject(IIsObjectPath)
  2449.  
  2450.         If (Err.Number <> 0) Then
  2451.                 ReportError ()
  2452.                 WScript.Echo "Error trying to get the path of the application: " & ObjectPath
  2453.                 WScript.Quit (Err.Number)
  2454.         End If
  2455.  
  2456.         IIsObject.AppEnable
  2457.  
  2458.         If (Err.Number <> 0) Then
  2459.                 ReportError ()
  2460.                 WScript.Echo "Error trying to Enable the application: " & ObjectPath
  2461.                 WScript.Quit (Err.Number)
  2462.         End If
  2463.  
  2464. 'debug
  2465. 'WScript.Echo "Last Error: " & Err & " (" & Hex (Err) & "): " & Err.Description
  2466.  
  2467.         WScript.Echo "Application Enabled."
  2468.  
  2469. End Function
  2470.  
  2471. '''''''''''''''''''''''''''''
  2472. ' AppGetStatusCommand
  2473. '''''''''''''''''''''''''''''
  2474. Function AppGetStatusCommand()
  2475.         On Error Resume Next
  2476.  
  2477.         Dim IIsObject
  2478.         Dim IIsObjectPath
  2479.         Dim ObjectPath
  2480.         Dim MachineName
  2481.         Dim Status
  2482.  
  2483.         AppGetStatusCommand = 0 ' Assume Success
  2484.  
  2485.         If ArgCount <> 2 Then
  2486.                 WScript.Echo "Error: Wrong number of Args for the APPGETSTATUS command"
  2487.                 WScript.Quit (GENERAL_FAILURE)
  2488.         End If
  2489.  
  2490.         ObjectPath = Args(1)
  2491.         SanitizePath ObjectPath
  2492.         MachineName = SeparateMachineName(ObjectPath)
  2493.  
  2494.         IIsObjectPath = "IIS://" & MachineName
  2495.         If ObjectPath <> "" Then
  2496.                 IIsObjectPath = IIsObjectPath & "/" & ObjectPath
  2497.         End If
  2498.  
  2499.         Set IIsObject = GetObject(IIsObjectPath)
  2500.  
  2501.         If (Err.Number <> 0) Then
  2502.                 ReportError ()
  2503.                 WScript.Echo "Error trying to get the path of the application: " & ObjectPath
  2504.                 WScript.Quit (Err.Number)
  2505.         End If
  2506.  
  2507.         Status = IIsObject.AppGetStatus2
  2508.  
  2509.         If (Err.Number <> 0) Then
  2510.                 ReportError ()
  2511.                 WScript.Echo "Error trying to retrieve the application STATUS: " & ObjectPath
  2512.                 WScript.Quit (Err.Number)
  2513.         End If
  2514.  
  2515.         WScript.Echo "Application Status: " & Status
  2516.  
  2517. End Function
  2518.  
  2519.                 
  2520.  
  2521.  ''''''''''''''''''''''''''
  2522. '
  2523. ' IsSecureProperty
  2524. '
  2525. ' Checks to see if the property requires special processing in order to
  2526. ' display its contents.
  2527. '
  2528. ''''''''''''''''''''''''''
  2529. Function IsSecureProperty(ObjectParameter,MachineName)
  2530.  
  2531.         On Error Resume Next
  2532.     Dim PropObj,Attribute
  2533.     Set PropObj = GetObject("IIS://" & MachineName & "/schema/" & ObjectParameter)
  2534.     If (Err.Number <> 0) Then
  2535.                 ReportError ()
  2536.                 WScript.Echo "Error trying to get the property: " & err.number
  2537.                 WScript.Quit (Err.Number)
  2538.         End If
  2539.     Attribute = PropObj.Secure
  2540.     If (Attribute = True) Then
  2541.         IsSecureProperty = True
  2542.     Else
  2543.         IsSecureProperty = False
  2544.     End If 
  2545. End Function