Create an IIS virtual site instance with VBS

Source: Internet
Author: User
iis| Create | Site |iis

' ---------------------------------------------------------------------------
' Creates or deletes the virtual directory Http://localhost/channel7
'
' Valid command line switches:-i-u-Q
'-I Install virtual directory
'-u Remove virtual directory
' Q-Run in quiet mode '
'
' ---------------------------------------------------------------------------
' http://www.microsoft.com/windows2000/en/advanced/iis/default.asp?url=/windows2000/en/advanced/iis/htm/asp/ Aore8v5e.htm

Option Explicit

Dim Vpath,vname, Vwshshell, Vobjargs, Vinstall, Vremove, Vquiet, I

VName = "Channel7"

' Get this path to folder
VPath = Left (Wscript.scriptfullname, InStrRev (wscript.scriptfullname, "\", 15)-1)
VPath = VPath & "\owbase"

' Set WshShell = WScript.CreateObject (' Wscript.Shell ')
' VPath = WshShell.RegRead ("Hklm\software\channel7") & "\owbase"

Vquiet = False
Vinstall = False
Vremove = False

Set Vobjargs = wscript.arguments

For i = 0 to Vobjargs.count-1
If InStr (LCase (Vobjargs (i)), "I") <> 0 Then
Vinstall = True
Elseif InStr (LCase (Vobjargs (i)), "U") <> 0 Then
Vremove = True
End If
If InStr (LCase (Vobjargs (i)), "Q") <> 0 Then
Vquiet = True
End If
Next

If Vremove Then
Deletevdir VName
Elseif Vinstall Then
Createvdir VName, VPath
End If


Sub Createvdir (pname, Ppath)
Dim VRoot, Vbasedir, Vwebsite, Ipsecurityobj, IPList

On Error Resume Next

' Get the local host default Web
Set vwebsite = GetObject ("IIS://LOCALHOST/W3SVC/1")
If not IsObject (vwebsite) Then
Display "Unable to locate" the Default Web Site. IIS must be installed and running. "
Exit Sub
Else
' Display vwebsite.name
End If

' Get the root '
Set vRoot = Vwebsite.getobject ("IIsWebVirtualDir", "Root")
If (Err <> 0) Then
Display "Unable to access root for" & Vwebsite.adspath
Exit Sub
Else
' Display vroot.name
End If

' Find or create ' ow vroot.
' The physical path to Http://localhost/ow are set to the ... <install-dir>\owbase folder
Err.Number = 0 ' Clear Error
Set Vbasedir = GetObject (Vroot.adspath & "/" + pname)
If err.number <> 0 Then
Err.Number = 0
Set Vbasedir = vroot.create ("IIsWebVirtualDir", PName)
Vbasedir.accessread = True
Vbasedir.accessflags = 513 ' = 0x200 + 0x01 = md_access_script + md_access_read
Vbasedir.appcreate False
Vbasedir.aspallowsessionstate = False
Vbasedir.setinfo ' This section restricts access to everyone except localhost (127.0.0.1).
' Set ipsecurityobj = vbasedir.ipsecurity
' Ipsecurityobj.grantbydefault = False
' IPList = ipsecurityobj.ipgrant
' ReDim iplist (UBound (iplist) + 1)
' IPList (UBound (iplist)) = "127.0.0.1"
' Ipsecurityobj.ipgrant = IPList
' vbasedir.ipsecurity = ipsecurityobj
' Vbasedir.setinfo

Vbasedir.path = Ppath
Vbasedir.appfriendlyname = "Channel7"
Vbasedir.setinfo

If (Err <> 0) Then
Display "Un



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.