Create a WebServer
'Required parameter: WRoot, which is the physical directory of the site to be created; WComment indicates the site description; WPort indicates the site port; ServerRun indicates whether the site runs automatically
'If the site is successfully created, 1 is returned. If the site fails to be created, 0 is returned. if the site is successfully created but the start fails, 2 is returned.
'*************************************** ***************
'
* Note: WPort is of the List type, indicating the server port.
'The function passed on IIS5.0. ** you must log on as an administrator **
'Example of Port:
'Dim WPort, bindlists, createflag, oComputer
'Ocomputer = "LocalHost """"
'Binglists = Array (0)
'Binglists (0) = ": 80:" 'port: 80
'Wport = binglists
'Createflag = CreateWebServer ("D: myweb", "My Home", WPort, False) 'calls the website creation Function
'If creatflag = 0 Then
'Response. Write "failed to create site! Please confirm whether you have the permission """"
'Elseif createflag = 1 Then
'Response. Write "site created successfully! """"
'Elseif createflag = 2 Then
'Response. Write "site created successfully, but failed to start the site. A port conflict may occur! """"
'End If
'*************************************** ******************
'The creation of an Ftp site has been published in asp. Please check it out by yourself.
'If you have any questions, please contact me: nonepassby@163.com
Function CreateWebServer (WRoot, WComment, WPort, ServerRun)
On Error Resume Next
Dim ServiceObj, ServerObj, VDirObj
Set ServiceObj = GetObject ("IIS: //" & oComputer & "/W3SVC") 'first creates 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) 'and then Create a WEB server
If (Err. Number <> 0) then' error?
'Response. Write "error: An error occurred while creating the ADSI operation for the Web server! """"
CreateWebServer = 0
Exit Function
End If
'Configure the server
ServerObj. ServerSize = 1' Medium Size
ServerObj. ServerComment = WComment 'description
ServerObj. ServerBindings = wport' Port
ServerObj. enabledefadoc Doc = True
'Submit Information
ServerObj. SetInfo
'Finally, create a virtual directory
Set VDirObj = ServerObj. Create ("IIsWebVirtualDir", "ROOT """")
If (Err. Number <> 0) then' error?
'Response. Write "error: ADSI operation failed to create virtual directory! """"
CreateWebServer = 0
Exit Function
End If
'Configure the virtual directory
VDirObj. Path = WRoot
VDirObj. AccessRead = True
VDirObj. AccessWrite = True
VDirObj. EnableDirBrowsing = False
VDirObj. enabledefadoc Doc = 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: An error occurred while starting the server! 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