VB.Net控制IIS的完整源代码

前端之家收集整理的这篇文章主要介绍了VB.Net控制IIS的完整源代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

每段都是一个文件代码如下:

  1. ImportsSystem
  2. ImportsSystem.DirectoryServices
  3. ImportsSystem.Collections
  4. NamespaceOPS.Component
  5. 'IISWebServer的状态
  6. PublicEnumIISServerState
  7. Starting=1
  8. Started=2
  9. Stopping=3
  10. Stopped=4
  11. Pausing=5
  12. Paused=6
  13. Continuing=7
  14. EndEnum
  15. EndNamespace
  1. ImportsSystem
  2. ImportsSystem.Collections
  3. ImportsSystem.Collections.Generic
  4. ImportsSystem.Text
  5. ImportsSystem.DirectoryServices
  6. NamespaceOPS.Component
  7. 'IISWebServer
  8. PublicClassIISWebServer
  9. FriendindexAsInteger=-1
  10. PublicWebVirtualDirsAsIISWebVirtualDirCollection
  11. '''<summary>
  12. '''网站说明
  13. '''</summary>
  14. PublicServerCommentAsString="Way"
  15. '''<summary>
  16. '''脚本支持
  17. '''</summary>
  18. PublicAccessScriptAsBoolean=True
  19. '''<summary>
  20. '''读取
  21. '''</summary>
  22. PublicAccessReadAsBoolean=True
  23. '''<summary>
  24. '''物理路径
  25. '''</summary>
  26. PublicPathAsString="c:/"
  27. '''<summary>
  28. '''端口
  29. '''</summary>
  30. PublicPortAsInteger=80
  31. '''<summary>
  32. '''目录浏览
  33. '''</summary>
  34. PublicEnableDirBrowsingAsBoolean=False
  35. '''<summary>
  36. '''默认文档
  37. '''</summary>
  38. PublicDefaultDocAsString="index.aspx"
  39. '''<summary>
  40. '''使用默认文档
  41. '''</summary>
  42. PublicEnableDefaultDocAsBoolean=True
  43. '''<summary>
  44. '''IISWebServer的状态
  45. '''</summary>
  46. PublicReadOnlyPropertyServerState()AsIISServerState
  47. Get
  48. DimserverAsDirectoryEntry=IISManagement.returnIISWebserver(Me.index)
  49. IfserverIsNothingThen
  50. Throw(NewException("找不到此IISWebServer"))
  51. EndIf
  52. SelectCaseserver.Properties("ServerState")(0).ToString()
  53. Case"2"
  54. ReturnIISServerState.Started
  55. Case"4"
  56. ReturnIISServerState.Stopped
  57. Case"6"
  58. ReturnIISServerState.Paused
  59. EndSelect
  60. ReturnIISServerState.Stopped
  61. EndGet
  62. EndProperty
  63. '''<summary>
  64. '''停止IISWebServer
  65. '''</summary>
  66. PublicSub[Stop]()
  67. DimServerAsDirectoryEntry
  68. Ifindex=-1Then
  69. Throw(NewException("在IIS找不到此IISWebServer!"))
  70. EndIf
  71. Try
  72. Server=NewDirectoryEntry("IIS://"+IISManagement.Machinename+"/W3SVC/"+index)
  73. IfServerIsNotNothingThen
  74. Server.Invoke("stop",NewObject(-1){})
  75. Else
  76. Throw(NewException("在IIS找不到此IISWebServer!"))
  77. EndIf
  78. Catch
  79. Throw(NewException("在IIS找不到此IISWebServer!"))
  80. EndTry
  81. EndSub
  82. '''<summary>
  83. '''把基本信息的更改更新到IIS
  84. '''</summary>
  85. PublicSubCommitChanges()
  86. IISManagement.EditIISWebServer(Me)
  87. EndSub
  88. '''<summary>
  89. '''启动IISWebServer
  90. '''</summary>
  91. PublicSubStart()
  92. Ifindex=-1Then
  93. Throw(NewException("在IIS找不到此IISWebServer!"))
  94. EndIf
  95. DimServiceAsNewDirectoryEntry("IIS://"+IISManagement.Machinename+"/W3SVC")
  96. DimServerAsDirectoryEntry
  97. DimieAsIEnumerator=Service.Children.GetEnumerator()
  98. Whileie.MoveNext()
  99. Server=DirectCast(ie.Current,DirectoryEntry)
  100. IfServer.SchemaClassName="IIsWebServer"Then
  101. IfServer.Properties("Serverbindings")(0).ToString()=":"+Me.Port+":"Then
  102. Server.Invoke("stop",NewObject(-1){})
  103. EndIf
  104. EndIf
  105. EndWhile
  106. Try
  107. Server=NewDirectoryEntry("IIS://"+IISManagement.Machinename+"/W3SVC/"+index)
  108. IfServerIsNotNothingThen
  109. Server.Invoke("start",NewObject(-1){})
  110. Else
  111. Throw(NewException("在IIS找不到此IISWebServer!"))
  112. EndIf
  113. Catch
  114. Throw(NewException("在IIS找不到此IISWebServer!"))
  115. EndTry
  116. EndSub
  117. PublicSubNew()
  118. WebVirtualDirs=NewIISWebVirtualDirCollection(Me)
  119. EndSub
  120. EndClass
  121. EndNamespace
  1. ImportsSystem
  2. ImportsSystem.Collections
  3. ImportsSystem.Collections.Generic
  4. ImportsSystem.Text
  5. NamespaceOPS.Component
  6. '''<summary>
  7. '''IISWebServerCollection
  8. '''</summary>
  9. PublicClassIISWebServerCollection
  10. InheritsCollectionBase
  11. DefaultPublicReadOnlyPropertyItem(ByValIndexAsInteger)AsIISWebServer
  12. Get
  13. ReturnDirectCast(Me.List(Index),IISWebServer)
  14. EndGet
  15. EndProperty
  16. DefaultPublicReadOnlyPropertyItem(ByValServerCommentAsString)AsIISWebServer
  17. Get
  18. ServerComment=ServerComment.ToLower().Trim()
  19. DimlistAsIISWebServer
  20. ForiAsInteger=0ToMe.List.Count-1
  21. list=DirectCast(Me.List(i),IISWebServer)
  22. Iflist.ServerComment.ToLower().Trim()=ServerCommentThen
  23. Returnlist
  24. EndIf
  25. Next
  26. ReturnNothing
  27. EndGet
  28. EndProperty
  29. FriendSubAdd_(ByValWebServerAsIISWebServer)
  30. Me.List.Add(WebServer)
  31. EndSub
  32. PublicSubAdd(ByValWebServerAsIISWebServer)
  33. Try
  34. Me.List.Add(WebServer)
  35. IISManagement.CreateIISWebServer(WebServer)
  36. Catch
  37. Throw(NewException("发生意外错误,可能是某节点将该节点的上级节点作为它自己的子级插入"))
  38. EndTry
  39. EndSub
  40. '''<summary>
  41. '''是否包含指定的网站
  42. '''</summary>
  43. '''<paramname="ServerComment"></param>
  44. '''<returns></returns>
  45. PublicFunctionContains(ByValServerCommentAsString)AsBoolean
  46. ServerComment=ServerComment.ToLower().Trim()
  47. ForiAsInteger=0ToMe.List.Count-1
  48. DimserverAsIISWebServer=Me(i)
  49. Ifserver.ServerComment.ToLower().Trim()=ServerCommentThen
  50. ReturnTrue
  51. EndIf
  52. Next
  53. ReturnFalse
  54. EndFunction
  55. '''<summary>
  56. '''是否包含指定的网站
  57. '''</summary>
  58. '''<paramname="index"></param>
  59. '''<returns></returns>
  60. PublicFunctionContains(ByValindexAsInteger)AsBoolean
  61. ForiAsInteger=0ToMe.List.Count-1
  62. DimserverAsIISWebServer=Me(i)
  63. Ifserver.index=indexThen
  64. ReturnTrue
  65. EndIf
  66. Next
  67. ReturnFalse
  68. EndFunction
  69. PublicSubAddRange(ByValWebServersAsIISWebServer())
  70. ForiAsInteger=0ToWebServers.GetUpperBound(0)
  71. Add(WebServers(i))
  72. Next
  73. EndSub
  74. PublicSubRemove(ByValWebServerAsIISWebServer)
  75. ForiAsInteger=0ToMe.List.Count-1
  76. IfDirectCast(Me.List(i),IISWebServer)=WebServerThen
  77. Me.List.RemoveAt(i)
  78. Return
  79. EndIf
  80. Next
  81. IISManagement.RemoveIISWebServer(WebServer.index)
  82. EndSub
  83. EndClass
  84. EndNamespace
  1. ImportsSystem
  2. ImportsSystem.Collections.Generic
  3. ImportsSystem.Text
  4. NamespaceOPS.Component
  5. '''<summary>
  6. '''IISWebVirtualDir
  7. '''</summary>
  8. PublicClassIISWebVirtualDir
  9. PublicParentAsIISWebServer=Nothing
  10. '''<summary>
  11. '''虚拟目录名称
  12. '''</summary>
  13. PublicNameAsString="Way"
  14. '''<summary>
  15. '''读取
  16. '''</summary>
  17. PublicAccessReadAsBoolean=True
  18. '''<summary>
  19. '''脚本支持
  20. '''</summary>
  21. PublicAccessScriptAsBoolean=True
  22. '''<summary>
  23. '''物理路径
  24. '''</summary>
  25. PublicPathAsString="c:/"
  26. '''<summary>
  27. '''默认文档
  28. '''</summary>
  29. PublicDefaultDocAsString="index.aspx"
  30. '''<summary>
  31. '''使用默认文档
  32. '''</summary>
  33. PublicEnableDefaultDocAsBoolean=True
  34. '''<summary>
  35. '''所属的网站的网站说明
  36. '''</summary>
  37. PublicWebServerAsString=""
  38. PublicSubNew(ByValWebServerNameAsString)
  39. IfWebServerName.ToString()=""Then
  40. Throw(NewException("WebServerName不能为空!"))
  41. EndIf
  42. Me.WebServer=WebServerName
  43. EndSub
  44. PublicSubNew()
  45. EndSub
  46. EndClass
  47. EndNamespace
  1. ImportsSystem
  2. ImportsSystem.Collections
  3. ImportsSystem.Collections.Generic
  4. ImportsSystem.Text
  5. NamespaceOPS.Component
  6. '''<summary>
  7. '''IISWebVirtualDirCollection
  8. '''</summary>
  9. PublicClassIISWebVirtualDirCollection
  10. InheritsCollectionBase
  11. PublicParentAsIISWebServer=Nothing
  12. DefaultPublicReadOnlyPropertyItem(ByValIndexAsInteger)AsIISWebVirtualDir
  13. Get
  14. ReturnDirectCast(Me.List(Index),IISWebVirtualDir)
  15. EndGet
  16. EndProperty
  17. DefaultPublicReadOnlyPropertyItem(ByValNameAsString)AsIISWebVirtualDir
  18. Get
  19. Name=Name.ToLower()
  20. DimlistAsIISWebVirtualDir
  21. ForiAsInteger=0ToMe.List.Count-1
  22. list=DirectCast(Me.List(i),IISWebVirtualDir)
  23. Iflist.Name.ToLower()=NameThen
  24. Returnlist
  25. EndIf
  26. Next
  27. ReturnNothing
  28. EndGet
  29. EndProperty
  30. FriendSubAdd_(ByValWebVirtualDirAsIISWebVirtualDir)
  31. Try
  32. Me.List.Add(WebVirtualDir)
  33. Catch
  34. Throw(NewException("发生意外错误,可能是某节点将该节点的上级节点作为它自己的子级插入"))
  35. EndTry
  36. EndSub
  37. PublicSubAdd(ByValWebVirtualDirAsIISWebVirtualDir)
  38. WebVirtualDir.Parent=Me.Parent
  39. Try
  40. Me.List.Add(WebVirtualDir)
  41. Catch
  42. Throw(NewException("发生意外错误,可能是某节点将该节点的上级节点作为它自己的子级插入"))
  43. EndTry
  44. IISManagement.CreateIISWebVirtualDir(WebVirtualDir,True)
  45. EndSub
  46. PublicSubAddRange(ByValWebVirtualDirsAsIISWebVirtualDir())
  47. ForiAsInteger=0ToWebVirtualDirs.GetUpperBound(0)
  48. Add(WebVirtualDirs(i))
  49. Next
  50. EndSub
  51. PublicSubRemove(ByValWebVirtualDirAsIISWebVirtualDir)
  52. ForiAsInteger=0ToMe.List.Count-1
  53. IfDirectCast(Me.List(i),IISWebVirtualDir)=WebVirtualDirThen
  54. Me.List.RemoveAt(i)
  55. IISManagement.RemoveIISWebVirtualDir(WebVirtualDir)
  56. Return
  57. EndIf
  58. Next
  59. EndSub
  60. PublicSubNew(ByValParentAsIISWebServer)
  61. Me.Parent=Parent
  62. EndSub
  63. EndClass
  64. EndNamespace
  1. ImportsSystem
  2. ImportsSystem.Collections
  3. ImportsSystem.Collections.Generic
  4. ImportsSystem.Text
  5. ImportsSystem.DirectoryServices
  6. NamespaceOPS.Component
  7. '''<summary>
  8. '''IISManagement的摘要说明。
  9. '''</summary>
  10. PublicClassIISManagement
  11. PublicWebServersAsNewIISWebServerCollection()
  12. FriendSharedMachinenameAsString="localhost"
  13. PublicSubNew()
  14. start()
  15. EndSub
  16. '''<paramname="MachineName">机器名,默认值为localhost</param>
  17. PublicSubNew(ByValMachineName__1AsString)
  18. IfMachineName__1.ToString()<>""Then
  19. Machinename=MachineName__1
  20. EndIf
  21. start()
  22. EndSub
  23. PrivateSubstart()
  24. DimServiceAsNewDirectoryEntry("IIS://"+Machinename+"/W3SVC")
  25. DimServerAsDirectoryEntry
  26. DimRootAsDirectoryEntry=Nothing
  27. DimVirDirAsDirectoryEntry
  28. DimieAsIEnumerator=Service.Children.GetEnumerator()
  29. DimieRootAsIEnumerator
  30. DimitemAsIISWebServer
  31. Dimitem_virdirAsIISWebVirtualDir
  32. DimfindedAsBoolean=False
  33. Whileie.MoveNext()
  34. Server=DirectCast(ie.Current,DirectoryEntry)
  35. IfServer.SchemaClassName="IIsWebServer"Then
  36. item=NewIISWebServer()
  37. item.index=Convert.ToInt32(Server.Name)
  38. item.ServerComment=DirectCast(Server.Properties("ServerComment")(0),String)
  39. item.AccessRead=CBool(Server.Properties("AccessRead")(0))
  40. item.AccessScript=CBool(Server.Properties("AccessScript")(0))
  41. item.DefaultDoc=DirectCast(Server.Properties("DefaultDoc")(0),String)
  42. item.EnableDefaultDoc=CBool(Server.Properties("EnableDefaultDoc")(0))
  43. item.EnableDirBrowsing=CBool(Server.Properties("EnableDirBrowsing")(0))
  44. ieRoot=Server.Children.GetEnumerator()
  45. WhileieRoot.MoveNext()
  46. Root=DirectCast(ieRoot.Current,DirectoryEntry)
  47. IfRoot.SchemaClassName="IIsWebVirtualDir"Then
  48. finded=True
  49. ExitWhile
  50. EndIf
  51. EndWhile
  52. IffindedThen
  53. item.Path=Root.Properties("path")(0).ToString()
  54. EndIf
  55. item.Port=Convert.ToInt32(DirectCast(Server.Properties("Serverbindings")(0),String).Substring(1,(DirectCast(Server.Properties("Serverbindings")(0),String)).Length-2))
  56. Me.WebServers.Add_(item)
  57. ieRoot=Root.Children.GetEnumerator()
  58. WhileieRoot.MoveNext()
  59. VirDir=DirectCast(ieRoot.Current,DirectoryEntry)
  60. IfVirDir.SchemaClassName<>"IIsWebVirtualDir"AndAlsoVirDir.SchemaClassName<>"IIsWebDirectory"Then
  61. ContinueWhile
  62. EndIf
  63. item_virdir=NewIISWebVirtualDir(item.ServerComment)
  64. item_virdir.Name=VirDir.Name
  65. item_virdir.AccessRead=CBool(VirDir.Properties("AccessRead")(0))
  66. item_virdir.AccessScript=CBool(VirDir.Properties("AccessScript")(0))
  67. item_virdir.DefaultDoc=DirectCast(VirDir.Properties("DefaultDoc")(0),String)
  68. item_virdir.EnableDefaultDoc=CBool(VirDir.Properties("EnableDefaultDoc")(0))
  69. IfVirDir.SchemaClassName="IIsWebVirtualDir"Then
  70. item_virdir.Path=DirectCast(VirDir.Properties("Path")(0),String)
  71. ElseIfVirDir.SchemaClassName="IIsWebDirectory"Then
  72. item_virdir.Path=Root.Properties("Path")(0)+"/"+VirDir.Name
  73. EndIf
  74. item.WebVirtualDirs.Add_(item_virdir)
  75. EndWhile
  76. EndIf
  77. EndWhile
  78. EndSub
  79. '''<summary>
  80. '''创建站
  81. '''</summary>
  82. '''<paramname="iisServer"></param>
  83. PublicSharedSubCreateIISWebServer(ByValiisServerAsIISWebServer)
  84. IfiisServer.ServerComment.ToString()=""Then
  85. Throw(NewException("IISWebServer的ServerComment不能为空!"))
  86. EndIf
  87. DimServiceAsNewDirectoryEntry("IIS://"+IISManagement.Machinename+"/W3SVC")
  88. DimServerAsDirectoryEntry
  89. DimiAsInteger=0
  90. DimieAsIEnumerator=Service.Children.GetEnumerator()
  91. Whileie.MoveNext()
  92. Server=DirectCast(ie.Current,DirectoryEntry)
  93. IfServer.SchemaClassName="IIsWebServer"Then
  94. IfConvert.ToInt32(Server.Name)>iThen
  95. i=Convert.ToInt32(Server.Name)
  96. EndIf
  97. EndIf
  98. EndWhile
  99. i+=1
  100. Try
  101. iisServer.index=i
  102. Server=Service.Children.Add(i.ToString(),"IIsWebServer")
  103. Server.Properties("ServerComment")(0)=iisServer.ServerComment
  104. Server.Properties("Serverbindings").Add(":"+iisServer.Port+":")
  105. Server.Properties("AccessScript")(0)=iisServer.AccessScript
  106. Server.Properties("AccessRead")(0)=iisServer.AccessRead
  107. Server.Properties("EnableDirBrowsing")(0)=iisServer.EnableDirBrowsing
  108. Server.Properties("DefaultDoc")(0)=iisServer.DefaultDoc
  109. Server.Properties("EnableDefaultDoc")(0)=iisServer.EnableDefaultDoc
  110. DimrootAsDirectoryEntry=Server.Children.Add("Root","IIsWebVirtualDir")
  111. root.Properties("path")(0)=iisServer.Path
  112. Service.CommitChanges()
  113. Server.CommitChanges()
  114. root.CommitChanges()
  115. root.Invoke("AppCreate2",NewObject(0){2})
  116. 'Server.Invoke("start",newobject[0]);
  117. CatchesAsException
  118. Throw(es)
  119. EndTry
  120. EndSub
  121. '''<summary>
  122. '''删除IISWebServer
  123. '''</summary>
  124. PublicSharedSubRemoveIISWebServer(ByValServerCommentAsString)
  125. DimServiceAsNewDirectoryEntry("IIS://"+IISManagement.Machinename+"/W3SVC")
  126. DimServerAsDirectoryEntry
  127. DimieAsIEnumerator=Service.Children.GetEnumerator()
  128. ServerComment=ServerComment.ToLower()
  129. Whileie.MoveNext()
  130. Server=DirectCast(ie.Current,DirectoryEntry)
  131. IfServer.SchemaClassName="IIsWebServer"Then
  132. IfServer.Properties("ServerComment")(0).ToString().ToLower()=ServerCommentThen
  133. Service.Children.Remove(Server)
  134. Service.CommitChanges()
  135. Return
  136. EndIf
  137. EndIf
  138. EndWhile
  139. EndSub
  140. '''<summary>
  141. '''删除IISWebServer
  142. '''</summary>
  143. PublicSharedSubRemoveIISWebServer(ByValindexAsInteger)
  144. DimServiceAsNewDirectoryEntry("IIS://"+IISManagement.Machinename+"/W3SVC")
  145. Try
  146. DimServerAsNewDirectoryEntry("IIS://"+IISManagement.Machinename+"/W3SVC/"+index)
  147. IfServerIsNotNothingThen
  148. Service.Children.Remove(Server)
  149. Service.CommitChanges()
  150. Else
  151. Throw(NewException("找不到此IISWebServer"))
  152. EndIf
  153. Catch
  154. Throw(NewException("找不到此IISWebServer"))
  155. EndTry
  156. EndSub
  157. '''<summary>
  158. '''检查是否存在IISWebServer
  159. '''</summary>
  160. '''<paramname="ServerComment">网站说明</param>
  161. '''<returns></returns>
  162. PublicSharedFunctionExistsIISWebServer(ByValServerCommentAsString)AsBoolean
  163. ServerComment=ServerComment.Trim()
  164. DimServiceAsNewDirectoryEntry("IIS://"+IISManagement.Machinename+"/W3SVC")
  165. DimServerAsDirectoryEntry=Nothing
  166. DimieAsIEnumerator=Service.Children.GetEnumerator()
  167. DimcommentAsString
  168. Whileie.MoveNext()
  169. Server=DirectCast(ie.Current,DirectoryEntry)
  170. IfServer.SchemaClassName="IIsWebServer"Then
  171. comment=Server.Properties("ServerComment")(0).ToString().ToLower().Trim()
  172. Ifcomment=ServerComment.ToLower()Then
  173. ReturnTrue
  174. EndIf
  175. EndIf
  176. EndWhile
  177. ReturnFalse
  178. EndFunction
  179. '''<summary>
  180. '''返回指定的IISWebServer
  181. '''</summary>
  182. '''<paramname="ServerComment"></param>
  183. '''<returns></returns>
  184. FriendSharedFunctionreturnIISWebserver(ByValServerCommentAsString)AsDirectoryEntry
  185. ServerComment=ServerComment.Trim()
  186. DimServiceAsNewDirectoryEntry("IIS://"+IISManagement.Machinename+"/W3SVC")
  187. DimServerAsDirectoryEntry=Nothing
  188. DimieAsIEnumerator=Service.Children.GetEnumerator()
  189. DimcommentAsString
  190. Whileie.MoveNext()
  191. Server=DirectCast(ie.Current,DirectoryEntry)
  192. IfServer.SchemaClassName="IIsWebServer"Then
  193. comment=Server.Properties("ServerComment")(0).ToString().ToLower().Trim()
  194. Ifcomment=ServerComment.ToLower()Then
  195. ReturnServer
  196. EndIf
  197. EndIf
  198. EndWhile
  199. ReturnNothing
  200. EndFunction
  201. '''<summary>
  202. '''返回指定的IISWebServer
  203. '''</summary>
  204. '''<paramname="index"></param>
  205. '''<returns></returns>
  206. FriendSharedFunctionreturnIISWebserver(ByValindexAsInteger)AsDirectoryEntry
  207. DimServerAsNewDirectoryEntry("IIS://"+IISManagement.Machinename+"/W3SVC/"+index)
  208. Try
  209. DimieAsIEnumerator=Server.Children.GetEnumerator()
  210. ReturnServer
  211. Catch
  212. ReturnNothing
  213. EndTry
  214. EndFunction
  215. PrivateSharedFunctiongetRoot(ByValServerAsDirectoryEntry)AsDirectoryEntry
  216. ForEachchildAsDirectoryEntryInServer.Children
  217. DimnameAsString=child.Name.ToLower()
  218. Ifname="iiswebvirtualdir"OrElsename="root"Then
  219. Returnchild
  220. EndIf
  221. Next
  222. ReturnNothing
  223. EndFunction
  224. '''<summary>
  225. '''修改与给定的IISWebServer具有相同网站说明的站点配置
  226. '''</summary>
  227. '''<paramname="iisServer">给定的IISWebServer</param>
  228. PublicSharedSubEditIISWebServer(ByValiisServerAsIISWebServer)
  229. IfiisServer.index=-1Then
  230. Throw(NewException("找不到给定的站点!"))
  231. EndIf
  232. DimServiceAsNewDirectoryEntry("IIS://"+IISManagement.Machinename+"/W3SVC")
  233. DimServerAsDirectoryEntry
  234. DimieAsIEnumerator=Service.Children.GetEnumerator()
  235. Whileie.MoveNext()
  236. Server=DirectCast(ie.Current,DirectoryEntry)
  237. IfServer.SchemaClassName="IIsWebServer"Then
  238. IfServer.Properties("Serverbindings")(0).ToString()=":"+iisServer.Port+":"Then
  239. Server.Invoke("stop",NewObject(-1){})
  240. EndIf
  241. EndIf
  242. EndWhile
  243. Server=returnIISWebserver(iisServer.index)
  244. IfServerIsNothingThen
  245. Throw(NewException("找不到给定的站点!"))
  246. EndIf
  247. Try
  248. Server.Properties("ServerComment")(0)=iisServer.ServerComment
  249. Server.Properties("Serverbindings")(0)=":"+iisServer.Port+":"
  250. Server.Properties("AccessScript")(0)=iisServer.AccessScript
  251. Server.Properties("AccessRead")(0)=iisServer.AccessRead
  252. Server.Properties("EnableDirBrowsing")(0)=iisServer.EnableDirBrowsing
  253. Server.Properties("DefaultDoc")(0)=iisServer.DefaultDoc
  254. Server.Properties("EnableDefaultDoc")(0)=iisServer.EnableDefaultDoc
  255. DimrootAsDirectoryEntry=getRoot(Server)
  256. Server.CommitChanges()
  257. IfrootIsNotNothingThen
  258. root.Properties("path")(0)=iisServer.Path
  259. root.CommitChanges()
  260. EndIf
  261. Server.Invoke("start",NewObject(-1){})
  262. CatchesAsException
  263. Throw(es)
  264. EndTry
  265. EndSub
  266. '''<summary>
  267. '''返回所有站点的网站说明
  268. '''</summary>
  269. '''<returns></returns>
  270. PublicSharedFunctionreturnIISServerComment()AsArrayList
  271. DimServiceAsNewDirectoryEntry("IIS://"+IISManagement.Machinename+"/W3SVC")
  272. DimServerAsDirectoryEntry
  273. DimlistAsNewArrayList()
  274. DimieAsIEnumerator=Service.Children.GetEnumerator()
  275. Whileie.MoveNext()
  276. Server=DirectCast(ie.Current,DirectoryEntry)
  277. IfServer.SchemaClassName="IIsWebServer"Then
  278. list.Add(Server.Properties("ServerComment")(0))
  279. EndIf
  280. EndWhile
  281. Returnlist
  282. EndFunction
  283. '''<summary>
  284. '''创建虚拟目录
  285. '''</summary>
  286. '''<paramname="iisVir"></param>
  287. '''<paramname="deleteIfExist"></param>
  288. PublicSharedSubCreateIISWebVirtualDir(ByValiisVirAsIISWebVirtualDir,ByValdeleteIfExistAsBoolean)
  289. IfiisVir.ParentIsNothingThen
  290. Throw(NewException("IISWebVirtualDir没有所属的IISWebServer!"))
  291. EndIf
  292. DimServiceAsNewDirectoryEntry("IIS://"+IISManagement.Machinename+"/W3SVC")
  293. DimServerAsDirectoryEntry=returnIISWebserver(iisVir.Parent.index)
  294. IfServerIsNothingThen
  295. Throw(NewException("找不到给定的站点!"))
  296. EndIf
  297. Server=getRoot(Server)
  298. IfdeleteIfExistThen
  299. ForEachVirDirAsDirectoryEntryInServer.Children
  300. IfVirDir.Name.ToLower().Trim()=iisVir.Name.ToLower()Then
  301. Server.Children.Remove(VirDir)
  302. Server.CommitChanges()
  303. ExitFor
  304. EndIf
  305. Next
  306. EndIf
  307. Try
  308. DimvirAsDirectoryEntry
  309. vir=Server.Children.Add(iisVir.Name,"IIsWebVirtualDir")
  310. vir.Properties("Path")(0)=iisVir.Path
  311. vir.Properties("DefaultDoc")(0)=iisVir.DefaultDoc
  312. vir.Properties("EnableDefaultDoc")(0)=iisVir.EnableDefaultDoc
  313. vir.Properties("AccessScript")(0)=iisVir.AccessScript
  314. vir.Properties("AccessRead")(0)=iisVir.AccessRead
  315. vir.Invoke("AppCreate2",NewObject(0){2})
  316. Server.CommitChanges()
  317. vir.CommitChanges()
  318. CatchesAsException
  319. Throw(es)
  320. EndTry
  321. EndSub
  322. '''<summary>
  323. '''删除虚拟目录
  324. '''</summary>
  325. '''<paramname="WebServerComment">站点说明</param>
  326. '''<paramname="VirtualDir">虚拟目录名称</param>
  327. PublicSharedSubRemoveIISWebVirtualDir(ByValWebServerCommentAsString,ByValVirtualDirAsString)
  328. VirtualDir=VirtualDir.ToLower()
  329. DimServiceAsNewDirectoryEntry("IIS://"+IISManagement.Machinename+"/W3SVC")
  330. DimServerAsDirectoryEntry=returnIISWebserver(WebServerComment)
  331. IfServerIsNothingThen
  332. Throw(NewException("找不到给定的站点!"))
  333. EndIf
  334. Server=getRoot(Server)
  335. ForEachVirDirAsDirectoryEntryInServer.Children
  336. IfVirDir.Name.ToLower().Trim()=VirtualDirThen
  337. Server.Children.Remove(VirDir)
  338. Server.CommitChanges()
  339. Return
  340. EndIf
  341. Next
  342. Throw(NewException("找不到给定的虚拟目录!"))
  343. EndSub
  344. '''删除虚拟目录
  345. PublicSharedSubRemoveIISWebVirtualDir(ByValiisVirAsIISWebVirtualDir)
  346. DimServiceAsNewDirectoryEntry("IIS://"+IISManagement.Machinename+"/W3SVC")
  347. DimServerAsDirectoryEntry=returnIISWebserver(iisVir.Parent.index)
  348. IfServerIsNothingThen
  349. Throw(NewException("找不到给定的站点!"))
  350. EndIf
  351. Server=getRoot(Server)
  352. ForEachVirDirAsDirectoryEntryInServer.Children
  353. IfVirDir.Name.ToLower().Trim()=iisVir.Name.ToLower()Then
  354. Server.Children.Remove(VirDir)
  355. Server.CommitChanges()
  356. Return
  357. EndIf
  358. Next
  359. Throw(NewException("找不到给定的虚拟目录!"))
  360. EndSub
  361. EndClass
  362. EndNamespace
PS:参考版为C#,来源已无法考证。 原文链接:https://www.f2er.com/vb/264002.html

猜你在找的VB相关文章