Background
I'm trying to automate the creation of Virtual Directories based on the location of an existing Virtual Directory and its sub-directories.
Example:
C:\WebSites\Parent\NewVirtualDirectories
Where Parent is a Virtual Directory and NewVirtualDirectories contains any automated Virtual Directories.
Problem
Using the following Code:
Option Explicit
Dim args, strComputer, strVdirName, strVdirPath, objVdir, objIIS, objWebSite
Set args = WScript.Arguments
strComputer = "localhost"
strVdirName = args(1)
strVdirPath = args(0)
Set objIIS = GetObject("IIS://" & strComputer & "/W3SVC/1")
Set objWebSite = objIIS.GetObject("IISWebVirtualDir","Root/Parent")
Set objVdir = objWebSite.Create("IISWebVirtualDir",strVdirName)
objVdir.AccessRead = True
objVdir.Path = strVdirPath
objVdir.AppCreate (True)
objVdir.SetInfo
WScript.Quit
I can create children under Parent, but they show up Directly under the parent. I need them to be in the Sub Folder.
I get: http://localhost/Parent/NewSite
I want: http://localhost/Parent/NewVirtualDirectories/NewSite
I've tried
Set objWebSite = objIIS.GetObject("IISWebVirtualDir","Root/Parent/NewVirtualDirectories")
but NewVirtualDirectories is not a Virtual Directory (an I don't want it to be) so I get an error. I can get the desired effect when I do this 开发者_开发百科manually in IIS manager, but I can't figure out how to automate it.
Any help would be greatly appreciated.
EDIT
For those who are facing similar problems, I found a great resource for VBScript-ing
http://www.cruto.com/resources/vbscript/vbscript-examples/vbscript-sitemap.asp
After doing a lot more digging (trial and error) I was able to figure it out.
By referencing the existing folder as a IISWebDirectory, I was able to select it and then create an application without creating a virtual directory.
Option Explicit
Dim args, strComputer, strVdirName, strVdirPath, objVdir, objIIS, objWebSite
Set args = WScript.Arguments
strComputer = "localhost"
strVdirName = args(1)
strVdirPath = args(0)
Set objIIS = GetObject("IIS://" & strComputer & "/W3SVC/1")
Set objVdir = objIIS.GetObject("IISWebDirectory","Root/Parent/NewVirtualDirectories/" + strVdirName)
objVdir.AccessRead = True
objVdir.AccessScript = True
objVdir.AppFriendlyName = strVdirName
objVdir.AppCreate (True)
objVdir.SetInfo
WScript.Quit
精彩评论