'************************************************ ****
'Create a WebServer
'Required parameters: WRoot, is the physical directory where the site is created; WComment is the site description; WPort is the site port; ServerRun is whether to run automatically
' Returns 1 when the creation is successful, prompts to exit and returns 0 when it fails, returns 2 when the site is created successfully but fails to start.
'************************************************ *****
'
'******************Note: WPort is List type, meaning server port
' This function passes on IIS5.0, **Must be logged in as administrator**
'Port example:
' Dim WPort,bindlists,createflag,oComputer
' oComputer=""""LocalHost""""
'binglists=Array(0)
' binglists(0)="""":80:""""'The port number is 80
' WPort=binglists
' createflag=CreateWebServer(""""D:myweb"""",""""My Home"""",WPort,False)'Call the website building function
' If creatflag=0 Then
' Response.Write """"Failed to create site! Please make sure you have permission""""
' ElseIf createflag=1 Then
' Response.Write """"Site created successfully! """"
' ElseIf createflag=2 Then
' Response.Write """"Creating the site successfully, but failing to start the site, there may be a port conflict! """"
'End If
'************************************************ **********
'About the creation of the Ftp site, I have published it in the asp version. Friends who are interested can check it out for themselves.
'If you have any questions, please feel free to contact me: [email protected]
Function CreateWebServer(WRoot,WComment,WPort,ServerRun)
On Error Resume Next
Dim ServiceObj,ServerObj,VDirObj
Set ServiceObj = GetObject(""""IIS://""""&oComputer&""""/W3SVC""")' First create a service instance
WNumber=1
Do While IsObject(ServiceObj.GetObject(""""IIsWebServer"""",WNumber))
If Err.number<>0 Then
Err.Clear()
Exit Do
End If
WNumber=WNumber+1
Loop
Set ServerObj = ServiceObj.Create(""""IIsWebServer"""", WNumber)' Then create a WEB serverIf
(Err.Number <> 0) Then' Is there an error?
'Response.Write """"Error: ADSI operation to create web server failed! """"
CreateWebServer=0
Exit Function
End If
' Then configure the server
ServerObj.ServerSize = 1 ' Medium size
ServerObj.ServerComment = WComment 'Description
ServerObj.ServerBindings = WPort 'Port
ServerObj.EnableDefaultDoc=True
' Submit information
ServerObj.SetInfo
' Finally, create a virtual directory
Set VDirObj = ServerObj.Create(""""IIsWebVirtualDir"""", """"ROOT"""")
If (Err.Number <> 0) Then' Is there an error?
'Response.Write """"Error: ADSI operation to create virtual directory failed! """"
CreateWebServer=0
Exit Function
End If
'Configure virtual directory
VDirObj.Path = WRoot
VDirObj.AccessRead = True
VDirObj.AccessWrite = True
VDirObj.EnableDirBrowsing = False
VDirObj.EnableDefaultDoc=True
VDirObj.AccessScript=True
VDirObj.AppCreate2 2
VDirObj.AppFriendlyName=""""Default Application""""
VDirObj.SetInfo
If ServerRun = True Then
ServerObj.Start
If (Err.Number <> 0) Then ' Error!
'Response.Write """"Error: Error starting server! Please start WebServer """"&WComment&"""" manually! <br>""""
CreateWebServer=2
Exit Function
End If
End If
Set VDirObj=Nothing
Set ServerObj=Nothing
Set ServiceObj=Nothing
CreateWebServer=1
End Function