home *** CD-ROM | disk | FTP | other *** search
/ Chip 2009 November / Chip_2009.11_CD.iso / I386 / ADSUTIL.VB_ / adsutil.vbs
Encoding:
Text File  |  2007-04-02  |  83.8 KB  |  2,633 lines

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