A class about IIS

zhaozj2021-02-16  57

Imports system

Imports System.directoryServices

Imports system.io

Public Class Iismanager

Public Shared Function CreateWebsite (Byval WEBSITENAME AS STRING) AS Website

DIM root as directoryentry = new DirectoryEntry ("IIS: // localhost / w3svc")

'Find Unused ID Value for New Web Site

DIM Siteid As INTEGER = 1

DIM E as DirectoryEntry

For Each E in root.children

If E.SChemaclassName = "IisWebserver" THEN

DIM ID as INTEGER = Convert.Toint32 (E.NAME)

IF id> = SiteId Then

SiteId = ID 1

END IF

END IF

NEXT

'Create the root directory and welcome html file

CreatePhysicalDirectory (Pathtoroot, Websitename)

'Create Web Site

Dim Site As New Website (CType (Root.invoke ("Create", "IisWebserver", SiteID, DirectoryEntry)

Site.serverComment = Websitename

'site.keytype = "iiswebserver"

Site.serverbindings = ": 80:" Websitename

Site.maxBandWidth = "1048576"

Site.serverstate = 2

Site.logflags.logextfileflags = 340871

Site.frontPageWeb = 1

'site.defaultdoc = "default.aspx"

'site.securebindings = ": 443:" Websitename

Site.serverautostart = 1

Site.serversize = 1

Site.setInfo ()

'Create Application Virtual Directory

DIM Sitevdir as DirectoryEntry = site.children.add ("root", "Iiswebvirtualdir")

Sitevdir.Properties ("Appisolated") (0) = 2

Sitevdir.Properties ("Path") (0) = PathToroot

Sitevdir.Properties ("AccessFlags") (0) = 513

Sitevdir.Properties ("FrontPageWeb") (0) = 1

Sitevdir.Properties ("approot") (0) = "/ lm / w3svc /" SiteId.tostring () "/root"'Sitevdir.properties ("AppfriendlyName" (0) = "root"

Sitevdir.commitchanges ()

Site.commitchanges ()

Sitevdir.Close ()

Site.close ()

'Create Temp Virtual Directory on Default Web Site

DIM DEROOT AS New DirectoryEntry ("IIS: // LocalHost / W3SVC / 1 / ROOT")

DEROOT.REFRESHCACHE ()

DIM DeNewvdir as DirectoryEntry = deeroot.children.add (Websitename.Replace ("." C, "-" c), "IisWebVirtualdir")

DeNewvdir.Properties ("path") (0) = pathtoroot

DeNewvdir.Properties ("AccessFlags") (0) = 513

DeNewvdir.Properties ("FrontPageWeb") (0) = 1

Denewvdir.commitchanges ()

Deroot.commitchanges ()

'Create a Application

Denewvdir.invoke ("AppCreate", True)

'Save Changes

Denewvdir.commitchanges ()

Deroot.commitchanges ()

Denewvdir.Close ()

DEROT.CLOSE ()

Return Site

END FUNCTION

Private Shared Sub CreatePhysicalDirectory (byval Pathtoroot As String, ByVal Websitename As String)

IF (Directory.exists (Pathtoroot) THEN

Throw New Exception ("Error Creating New Website: Customer Root Directory Already Exists At" Pathtoroot)

Else

Directory.createdIRectory (Pathtoroot)

DIM INDEXFILE AS New StreamWriter (Pathtoroot /index.htm ", false, system.text.Encoding.ascii

Indexfile.write ("

Welcome to " Websitename "

")

Indexfile.close ()

END IF

End Sub

END CLASS

Public Class Website

Public Sub New (Byval ObjdirectoryEntry As DirectoryEntry)

Site = ObjDirectoryEntry

LogfileFlags = New LogextFileFlags (ObjdirectoryEntry)

End Sub

Private site as DirectoryEntry

Private logfileflags as LogextFileFlagspublic Readonly property logflags () as LogextFileFlags

Get

Return logfileflags

END GET

End Property

Public property servercomment () AS String

Get

Return CType (Site.Properties ("Servercomment") (0), String)

END GET

Set (byval value as string)

Site.Invoke ("Put", "Servercomment", Value)

End set

End Property

Public property keytype () AS STRING

Get

Return CType (Site.Properties ("KeyType") (0), String)

END GET

Set (byval value as string)

Site.Invoke ("Put", "Keytype", Value)

End set

End Property

Public property serverbindings () AS STRING

Get

Return CType (Site.properties ("ServerBindings") (0), String)

END GET

Set (byval value as string)

Site.Invoke ("Put", "Serverbindings", Value)

End set

End Property

Public property defaultdoc () AS STRING

Get

Return CType (Site.properties ("defaultdoc") (0), String)

END GET

Set (byval value as string)

Site.Invoke ("Put", "DefaultDoc", Value

End set

End Property

Public property maxbandwidth () AS STRING

Get

Return CType (Site.Properties ("MaxBandwidth") (0), String)

END GET

Set (byval value as string)

Site.Invoke ("Put", "MaxBandwidth", Value

End set

End Property

Public property serverstate () AS INT32

Get

Return CType (Site.properties ("Serverstate") (0), INT32)

END GET

Set (byval value as int32)

Site.Invoke ("Put", "Serverstate", Value)

End set

End Property

Public property frontPageWeb () AS INT32

Get

Return CType (Site.properties ("FrontPageWeb") (0), INT32)

END GET

Set (byval value as int32)

Site.Invoke ("Put", "FrontPageWeb", Value)

End set

End Property

Public property secondbindings () AS STRINGET

Return CType (Site.Properties ("SecureBindings") (0), String)

END GET

Set (byval value as string)

Site.Invoke ("Put", "SecureBindings", Value

End set

End Property

Public property serverautostart () AS INT32

Get

Return CType (Site.Properties ("ServerAutostart") (0), INT32)

END GET

Set (byval value as int32)

Site.Invoke ("Put", "Serverautostart", Value

End set

End Property

Public property serversize () AS INT32

Get

Return CType (Site.Properties ("Serversize") (0), INT32)

END GET

Set (byval value as int32)

Site.Invoke ("Put", "Serversize", Value)

End set

End Property

Public Readonly Property Children () AS DirectoryEntries

Get

Return Site.Children

END GET

End Property

Public Readonly Property Name () AS String

Get

Return Site.name

END GET

End Property

Public Sub Commitchanges ()

Site.commitchanges ()

End Sub

Public Sub setInfo ()

Site.Invoke ("setInfo")

End Sub

Public Sub Close ()

Site.close ()

End Sub

END CLASS

Public Class LogextFileFlags

Public Sub New (Byval ObjdirectoryEntry As DirectoryEntry)

Site = ObjDirectoryEntry

End Sub

Private site as DirectoryEntry

Public property LogextFileFlags () AS INT32

Get

Return CType (Site.Properties ("LogextFileFlags") (0), INT32)

END GET

Set (byval value as int32)

Site.Invoke ("Put", "LogextFileFlags", Value

End set

End Property

'Public property LogextFileBytesRecv () AS Boolean

'Get

'Return CBool ​​(Site.Properties ("LogextFileBytesRecv") (0))

'End Get

'Set (Byval Value as Boolean)

'Dim showinlog as int32 = 0

'IF value kil

'ShowinLog = 1' end if

'Site.invoke ("Put", "LogextFileBytesRecv", ShowinLog

'End set

'End Property

END CLASS

转载请注明原文地址:https://www.9cbs.com/read-25211.html

New Post(0)