Hi,
The code in your previous post did not show how to achieve this task. The following JavaScript sample convert the plain folder "susan" to an application. Most of codes are generated by Configuration Editor shipped with Administration Pack, you can do some test to see if it work for you.
If you must to use Vbscript, you need to convert the Jscript to Vbscript manually.
The Code samples in the following article are presented in five languages, for your reference:
http://www.iis.net/ConfigReference/system.applicationHost/applicationPools
var masterdomain= "mydomain.com";
var sitename= "stores.mydomain.com";
var apool= "mydomain.com(domain)(2.0)(pool)";
var freetrialfolder= "susan";
var apath= "/" + freetrialfolder;
var phypath= "D:\\inetpub\\vhosts\\" + masterdomain + "\\httpdocs\\stores\\" + freetrialfolder;
var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
//create the application pool
var applicationPoolsSection = adminManager.GetAdminSection("system.applicationHost/applicationPools", "MACHINE/WEBROOT/APPHOST");
var applicationPoolsCollection = applicationPoolsSection.Collection;
var addElement = applicationPoolsCollection.CreateNewElement("add");
addElement.Properties.Item("name").Value = apool;
applicationPoolsCollection.AddElement(addElement);
adminManager.CommitChanges();
//Convert the plain folder to an application
var sitesSection = adminManager.GetAdminSection("system.applicationHost/sites", "MACHINE/WEBROOT/APPHOST");
var sitesCollection = sitesSection.Collection;
var siteElementPos = FindElement(sitesCollection, "site", ["name", sitename]);
if (siteElementPos == -1) throw "Element not found!";
var siteElement = sitesCollection.Item(siteElementPos);
var siteCollection = siteElement.Collection;
var applicationElement = siteCollection.CreateNewElement("application");
applicationElement.Properties.Item("path").Value = apath;
applicationElement.Properties.Item("applicationPool").Value = apool;
var applicationCollection = applicationElement.Collection;
var virtualDirectoryElement = applicationCollection.CreateNewElement("virtualDirectory");
virtualDirectoryElement.Properties.Item("path").Value = "/";
virtualDirectoryElement.Properties.Item("physicalPath").Value = phypath;
applicationCollection.AddElement(virtualDirectoryElement);
siteCollection.AddElement(applicationElement);
adminManager.CommitChanges();
function FindElement(collection, elementTagName, valuesToMatch) {
for (var i = 0; i < collection.Count; i++) {
var element = collection.Item(i);
if (element.Name == elementTagName) {
var matches = true;
for (var iVal = 0; iVal < valuesToMatch.length; iVal += 2) {
var property = element.GetPropertyByName(valuesToMatch[iVal]);
var value = property.Value;
if (value != null) {
value = value.toString();
}
if (value != valuesToMatch[iVal + 1]) {
matches = false;
break;
}
}
if (matches) {
return i;
}
}
}
return -1;
}
If you have any problem , please update here.