Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2544 lines
89 KiB

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