恍惚之间

梦...

Invoke("stop", Nothing)关闭某端口

Try
            
Dim root As DirectoryEntry = New DirectoryEntry("IIS://localhost/W3SVC")
            
Dim siteID As Integer = 1
            
Dim e As New DirectoryEntry
            
For Each e In root.Children
                
If e.SchemaClassName = "IIsWebServer" Then
                    
Dim ID As Integer = Convert.ToInt32(e.Name)
                    
Dim obj As New Object
                    
If ID >= siteID Then
                        siteID 
= ID + 1
                    
End If
                   
If e.Properties("ServerBindings")(0).ToString() = ":" + port + ":" Then
                        
'关闭具有同样端口的站点-------
                        Dim mysiteID As Integer = siteID - 1
                        
Dim siteStop As DirectoryEntry = New DirectoryEntry("IIS://localhost/W3SVC/" + mysiteID.ToString)     
                        siteStop.Invoke("stop"Nothing)   '关闭
             
       End If
                
End If
            
Next

            
Dim site As DirectoryEntry = root.Invoke("Create""IIsWebServer", siteID)               site.Invoke("Put""ServerComment", webSiteName)
            site.Invoke(
"Put""KeyType""IIsWebServer")
            site.Invoke(
"Put""ServerBindings"":" + port + ":")
            site.Invoke(
"Put""ServerState"2)
            site.Invoke(
"Put""FrontPageWeb"1)
            site.Invoke(
"Put""DefaultDoc""index.aspx")
            
'   site.Invoke("Put", "SecureBindings", ":443:")   'SLL端口
            site.Invoke("Put""ServerAutoStart"1)
            site.Invoke(
"Put""ServerSize"1)
            site.Invoke(
"SetInfo")
            
Dim siteVDir As DirectoryEntry = site.Children.Add("Root""IISWebVirtualDir")
            siteVDir.Properties(
"AppIsolated")(0= 2
            siteVDir.Properties(
"Path")(0= path
            siteVDir.Properties(
"AccessFlags")(0= 513
            siteVDir.Properties(
"FrontPageWeb")(0= 1
          
  siteVDir.Properties("AppFriendlyName")(0= "ROOT"
            siteVDir.CommitChanges()
            site.CommitChanges()
        
Catch ex As Exception
            
Throw ex
        
End Try
    
End Sub

posted on 2006-11-23 20:52  Red Hu  阅读(...)  评论(...编辑  收藏

My Links

Blog Stats