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#,来源已无法考证。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强制返回为文本 -------------------------------- 数字类型的格式化 --------------------------------     固定格式参数:     General Number 普通数字,如可以用来去掉千位分隔号     format$("100,1
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办法, Format 或者FormatDateTime 竟然结果和系统设置的区域语言的日期和时间格式相关。意思是尽管你用诸如 Format(Now, "MM/dd/yyyy"),如果系统的设置格式区域语言的日期和时间格式分隔符是"-",那他还会显示为 MM-dd-yyyy     只有拼凑: <%response.write
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace My ‘全局错误处理,新的解决方案直接添加本ApplicationEvents.vb 到工程即可 ‘添加后还需要一个From用来显示错误。如果到这步还不会则需要先打好基础啦 ‘======================================================== ‘以下事件
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用的爽呀,这篇文章写与2011年,看来我以前没有认真去找这个方法呀。 https://blog.csdn.net/chzjxgd/article/details/6176325 金蝶K3 BOS的插件官方是用VB6编写的,如果  能用.Net下的语言工具开发BOS插件是一件很愉快的事情,其中缘由不言而喻,而本文则是个人首创,实现在了用V
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选中的单元格进行处理 Dim m As Range, tmpStr As String, s As String Dim x As Integer, y As Integer, subStr As String If MsgBox("确定要分列处理吗?请确定分列的数据会覆盖它后面的单元格!", _
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single) 2 Dim path As String, hash As String 3 For Each fil
  Imports MySql.Data.MySqlClient Public Class Form1 ‘ GLOBAL DECLARATIONS Dim conString As String = "Server=localhost;Database=net2;Uid=root;Pwd=123456;" Dim con As New MySqlConnection
‘導入命名空間 Imports ADODB Imports Microsoft.Office.Interop   Private Sub A1() Dim Sql As String Dim Cnn As New ADODB.Connection Dim Rs As New ADODB.Recordset Dim S As String   S = "Provider=OraOLEDB.Oracl
Imports System.IO Imports System.Threading Imports System.Diagnostics Public Class Form1 Dim A(254) As String    Function ping(ByVal IP As Integer) As String Dim IPAddress As String IPAddress = "10.0.
VB运行EXE程序,并等待其运行结束 参考:https://blog.csdn.net/useway/article/details/5494084 Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long Pr
今天碰到一个问题,登陆的时候,如果不需要验证手机号为空,则不去验证手机号 因为登陆的时候所有的验证信息都存放在一个数组里 Dim CheckUserInfo() As String ={UserBirthday, SecEmail, UserMob, UserSex, RealNameFirst, RealName, CheckCardID, CheckCardType, Contactemail
在VB6.0中,数据访问接口有三种: 1、ActiveX数据对象(ADO) 2、远程数据对象(RDO) 3、数据访问对象(DAO) 1.使用ADO(ActiveX Data Objec,ActiveX数据对象)连接SQL Server 1)使用ADO控件连接 使用ADO控件的ConnectionString属性就可以连接SQL Server,该属性包含一个由分号分隔的argument=value语
注:大家如果没有VB6.0的安装文件,可自行百度一下下载,一般文件大小在200M左右的均为完整版的软件,可以使用。   特别提示:安装此软件的时候最好退出360杀毒软件(包括360安全卫士,电脑管家等,如果电脑上有这些软件的话),因为现如今的360杀毒软件直接会对VB6.0软件误报,这样的话就可能会在安装过程中被误报阻止而导致安装失败,或者是安装后缺乏很多必须的组件(其它的杀毒软件或安全卫士之类的
Private Sub Form_Load() Call conndb End Sub Private Function conndb() Dim cn As New ADODB.Connection Dim rs As New ADODB.Recordset Dim strCn, sql As String Dim db_host As String Dim db_user As String
  PPSM06S70:  Add  moddate  EDITSPRINTJOB:  MAX(TO_CHAR(ETRN.MODDATE, ‘yyyy/mm/dd/HH24:MI AM‘)) ACTUAL_SHIPDATE   4.Test Scenario (1) :Query SQL Test DN:8016578337 SELECT CTRN.TKCTID TRUCK_ID,        
  沒有出現CrystalReportViewer時,須安裝CRforVS_13_0. 新增1個數據集,新增1個數據表,添加二列,列名要和資料庫名一樣. 修改目標Framework 修改app.config, <startup >改成<startup useLegacyV2RuntimeActivationPolicy ="true">  CrystalReport1.rpt增加數據庫專家 在表單
Imports System.Threading Imports System Public Class Form1 Dim th1, th2 As Thread Public Sub Method1() Dim i As Integer For i = 1 To 100 If Me.Label1.BackColor =
Friend Const PROCESS_ALL_ACCESS = &H1F0FFF = 2035711 Friend Const PROCESS_VM_READ = &H10 Friend Const PROCESS_VM_WRITE = &H20 Friend Const PAGE_READONLY = &H2 Friend Const PAGE_READWRITE = &H4 Friend
以下代码随手写的 并没有大量测试 效率也有待提升 如果需要C#的请自行转换 Function SplitBytes(Data As Byte(), Delimiter As Byte()) As List(Of Byte()) Dim i = 0 Dim List As New List(Of Byte()) Dim bytes As New
Imports System.Data.SqlClient Public Class Form1 REM Public conn1 As SqlConnection = New SqlConnection("server=.; Integrated Security=False;Initial Catalog= mydatabase1; User ID= sa;password")