Leaked source code of windows server 2003
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.

209 lines
5.9 KiB

  1. '''''''''''''''''''''''''''''''''''''''''''''
  2. '
  3. ' IWAM account synchronization utility
  4. '
  5. '''''''''''''''''''''''''''''''''''''''''''''
  6. ' Description:
  7. ' ------------
  8. ' This admin script allows you to update the launching identity of
  9. ' all IIS COM+ application packages that run out of process.
  10. '
  11. ' There are certain operations that may cause the IWAM account, which
  12. ' is the identity under which out of process IIS applications run, to
  13. ' become out of sync between the COM+ data store and IIS or the SAM.
  14. ' On IIS startup the account information stored in the IIS Metabase
  15. ' is synchronized with the local SAM, but the COM+ applications will
  16. ' not automatically be updated. The result of this is that requests
  17. ' to out of process applications will fail.
  18. '
  19. ' When this happens, the following events are written to the system
  20. ' event log:
  21. '
  22. ' Event ID: 10004 Source: DCOM
  23. ' DCOM got error "Logon failure: unknown user name or bad password. "
  24. ' and was unable to logon .\IWAM_MYSERVER in order to run the server:
  25. ' {1FD7A201-0823-479C-9A4B-2C6128585168}
  26. '
  27. ' Event ID: 36 Source: W3SVC
  28. ' The server failed to load application '/LM/W3SVC/1/Root/op'.
  29. ' The error was 'The server process could not be started because
  30. ' the configured identity is incorrect. Check the username and password.
  31. '
  32. ' Running this utility will update the COM+ applications with the
  33. ' correct identity.
  34. '
  35. ' To Run:
  36. ' -------
  37. ' This is the format for this script:
  38. '
  39. ' cscript synciwam.vbs [-v|-h]
  40. ' -v verbose: print a trace of the scripts activity
  41. ' -h help: print script usage
  42. '
  43. ' NOTE: If you want to execute this script directly from Windows, use
  44. ' 'wscript' instead of 'cscript'.
  45. '
  46. '''''''''''''''''''''''''''''''''''''''''''''
  47. ' Initialize error checking
  48. On Error Resume Next
  49. Const APP_ISOLATED = 1
  50. Const APP_OOP_POOL_ID = "{3D14228D-FBE1-11d0-995D-00C04FD919C1}"
  51. Const IIS_ANY_PROPERTY = 0
  52. Dim WebServiceObj, WamUserName, WamUserPass
  53. Dim ComCatalogObj, ComAppCollectionObj, ComApplication
  54. Dim AppIdArray, AppIdArraySize, AppIdArrayElements
  55. Dim IISAppPathArray, IISAppObj, IISAppPath
  56. Dim TraceEnabled
  57. ' Get command line parameters
  58. TraceEnabled = False
  59. if Wscript.Arguments.Count > 0 then
  60. select case WScript.Arguments(0)
  61. case "-h", "-?", "/?":
  62. PrintUsage
  63. case "-v", "/v":
  64. TraceEnabled = True
  65. case else
  66. PrintUsage
  67. end select
  68. end if
  69. ' Get a reference to the web service object
  70. set WebServiceObj = GetObject("IIS://LocalHost/w3svc")
  71. QuitOnError()
  72. ' Save the wam user name and password
  73. WamUserName = WebServiceObj.WAMUserName
  74. WamUserPass = WebServiceObj.WAMUserPass
  75. QuitOnError()
  76. ' Assume that a blank password or user is an error
  77. if WamUserName = "" or WamUserPass = "" then
  78. WScript.Echo "Error: Empty user name or password."
  79. WScript.Quit(1)
  80. end if
  81. ' The com+ packages that we want to set are those that run in external
  82. ' processes. These include the process pool application and any isolated
  83. ' applications defined for this server.
  84. IISAppPathArray = WebServiceObj.GetDataPaths( "AppIsolated", IIS_ANY_PROPERTY )
  85. QuitOnError()
  86. AppIdArraySize = UBound(IISAppPathArray) + 1
  87. Redim AppIdArray( AppIdArraySize )
  88. ' Set the id for the pooled application
  89. AppIdArrayElements = 0
  90. AppIdArray(AppIdArrayElements) = APP_OOP_POOL_ID
  91. AppIdArrayElements = AppIdArrayElements + 1
  92. ' Get the ids for all isolated applications
  93. Trace "IIS Applications Defined: "
  94. Trace "Name, AppIsolated, Package ID"
  95. for each IISAppPath in IISAppPathArray
  96. set IISAppObj = GetObject( IISAppPath )
  97. Trace IISAppObj.Name & ", " & CStr(IISAppObj.AppIsolated) & ", " & CStr(IISAppObj.AppPackageID)
  98. if APP_ISOLATED = IISAppObj.AppIsolated And IISAppObj.AppPackageID <> "" then
  99. AppIdArray(AppIdArrayElements) = IISAppObj.AppPackageID
  100. AppIdArrayElements = AppIdArrayElements + 1
  101. end if
  102. set IISAppObj = Nothing
  103. next
  104. Trace ""
  105. ' Readjust the size of the id array. The size is initially set
  106. ' larger than it needs to be. So we will reduce it so com+ does
  107. ' not have to do more work than necessary
  108. Redim Preserve AppIdArray(AppIdArrayElements)
  109. ' Dump the array of application ids
  110. if TraceEnabled then
  111. WScript.Echo "Out of process applications defined: "
  112. WScript.Echo "Count: " & CStr(AppIdArrayElements)
  113. for i = 0 to AppIdArrayElements - 1
  114. WScript.Echo AppIdArray(i)
  115. next
  116. WScript.Echo ""
  117. end if
  118. ' Init com admin objects
  119. set ComCatalogObj = CreateObject( "COMAdmin.COMAdminCatalog" )
  120. QuitOnError()
  121. set ComAppCollectionObj = ComCatalogObj.GetCollection( "Applications" )
  122. QuitOnError()
  123. ComAppCollectionObj.PopulateByKey( AppIdArray )
  124. QuitOnError()
  125. ' Update the com applications
  126. Trace "Updating Applications: "
  127. for each ComApplication in ComAppCollectionObj
  128. Trace "Name: " & ComApplication.Name & " Key: " & CStr(ComApplication.Key)
  129. ReportErrorAndContinue()
  130. ComApplication.Value("Identity") = WamUserName
  131. ReportErrorAndContinue()
  132. ComApplication.Value("Password") = WamUserPass
  133. ReportErrorAndContinue()
  134. next
  135. ComAppCollectionObj.SaveChanges
  136. QuitOnError()
  137. '''''''''''''''''''''''''''''''''''''''''''''
  138. ' Helper functions
  139. '
  140. sub QuitOnError()
  141. if err <> 0 then
  142. WScript.Echo "Error: " & Hex(err) & ": " & err.description
  143. Wscript.Quit(1)
  144. end if
  145. end sub
  146. sub ReportErrorAndContinue()
  147. if err <> 0 then
  148. WScript.Echo "Error: " & Hex(err) & ": " & err.description
  149. err.Clear
  150. end if
  151. end sub
  152. sub Trace( str )
  153. if TraceEnabled then
  154. WScript.Echo CStr(str)
  155. end if
  156. end sub
  157. sub PrintUsage()
  158. Wscript.Echo "Usage: cscript synciwam.vbs [-v|-h]"
  159. Wscript.Echo vbTab & "-v verbose: trace execution of the script"
  160. Wscript.Echo vbTab & "-h help: print this message"
  161. WScript.Quit(0)
  162. end sub