Now when I deploy a virtual directory with nested(child) virtual directories, it works fine. (using InstallShield)
But I have a problem when I try it re-install it.
After a successfully deploy, I want to fully re-deploy, so I
Go to IIS Manager and right-mouse-click the deployed parent virtual folder, then select
Deploy-> Delete Application and Content
This removes the deployed parent virtual directory from the IIS Metabase and the all relevant physical folders.
But if I run the script below I can still see the deployed nested virtual directories, but not the parent virtual directory.
If I add the parent virtual directory and nested virtual directories through IIS Manager, Deploy-> Delete Application and Content then run the script below again; then neither parent virtual directory nor nested virtual directories are in the IIS MetaBase.
I want my script to behave like IIS Manager when I add nested set of virtual directories,
It may not be me or my script that removes the deployed nested set of virtual directories via IIS Manager.
So I am obviously missing a property setting somewhere.
For this post Assume that the IIS version is 7.5 ( ours is)
Regards
Greg Frazer
//The script code:
webite = "Default Web Site"
vDir = "Install40"
TARGETDIR = "C:\inetpub\wwwroot\" & vDir
vDir = "/" & vDir
'//configure IIS for the application
nResult = CreateIISApp(webite, vDir, TARGETDIR, vDir)
Wscript.Echo "nResult= " & nResult
'// Do the same for the Web
nResult = CreateIISApp(webite, vDir & "/Web", TARGETDIR & "\Web", "Web")
Wscript.Echo "nResult= " & nResult
function CreateIISApp(sWebSite, sVirDirName, sFolder, sFriendlyName)
dim sVersions(3)
dim sThisVersion
dim sScriptMaps
dim sPoolName
dim nResult, n1, n2
dim oRootDir, oWebSite, oVirDir, oScriptMaps, oThisScriptMap
Err.Clear
'//Check to see if the website exists.
nResult = CheckWebSite(sWebSite, oWebSite)
if nResult <> 0 then
CreateIISApp = nResult
exit function
end if
'//Check to see if the application pool exists. Create it if necessary.
nResult = CheckAppPool(sPoolName,sFriendlyName)
if nResult <> 0 then
CreateIISApp = nResult
exit function
end if
nResult = 0
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")
' Use InstancesOf to retrieve the applications.
Set oApps = oWebAdmin.InstancesOf("Application")
' Iterate through the applications.
For Each oApp In oApps
if(sVirDirName = oApp.Path) then
Wscript.Echo sVirDirName
CreateIISApp = 1
exit function
end if
Next
' Create the new application
oWebAdmin.Get("Application").Create sVirDirName, sWebSite, sFolder
' Iterate through the applications.
Set oApps = oWebAdmin.InstancesOf("Application")
For Each oApp In oApps
if(sVirDirName = oApp.Path) then
Wscript.Echo " inside: " & sVirDirName
oApp.ApplicationPool = sPoolName
oApp.Put_
' create the physical path if it does not exist
set filesys = CreateObject("Scripting.FileSystemObject")
If Not filesys.FolderExists(sFolder) Then
Set newfolder = filesys.CreateFolder(sFolder)
Wscript.Echo "newfolder: " & newfolder
End If
CreateIISApp = 6
exit function
end if
Next
CreateIISApp = 0
exit function
end function
'//---------------------------------------------------------------------------
'// CheckAppPool
'//
'// Tries to get the pool to be used by the IIS application. Creates it if one doesn't already exist
'//
'//---------------------------------------------------------------------------
function CheckAppPool(sPoolName,sFriendlyName)
dim oAppPoolList
dim oAppPool
dim varEnum
dim nResult
on error resume next
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")
'//IIS application pools are only supported from version 6 on Windows 2003. Therefore just leave.
'//if (IISRTGetIISVersion(IIS_GET_VERSION_MAJOR) < 6) then
'///NOTE For this post assume only ISS 7.0 and greater
'// return 0;
'//endif;
sPoolName = "MyCompanyAppPoolV4"
' Retrieve the default App Pool.
getParam = "ApplicationPool.Name='" & sPoolName & "'"
Set oAppPool = oWebAdmin.Get(getParam)
if(not oAppPool is nothing) then
CheckAppPool = 0
exit function
end if
'//does exist so create it
oWebAdmin.Get("ApplicationPool").Create(sPoolName)
Set oAppPool = oWebAdmin.Get(getParam)
if oAppPool is NOTHING then
'//Failed to create AppPool
CheckAppPool = 12
exit function
end if
oAppPool.Put_
'//Created IIS Application Pool
CheckAppPool = 0
end function
'//---------------------------------------------------------------------------
'// CheckWebSite
'//
'// Search the computer for a specific website and return the web site object
'//
'//---------------------------------------------------------------------------
function CheckWebSite(sWebSite, oWebSite)
dim oWebSvc
dim varEnum
on error resume next
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")
if (oWebAdmin is nothing) then
'// Failed to find IIS Object
CheckWebSite = 9
exit function
end if
' Retrieve the web site.
getParam = "Site.Name='" & sWebSite & "'"
Set webSite = oWebAdmin.Get(getParam)
if(not webSite is nothing) then
set oWebSite = webSite
CheckWebSite = 0
exit function
end if
'// We should go onto create the website, but for now return an error stating that the website couldn't be found
CheckWebSite = 10
In this case, the script create two applications instead of two virtual directories. As the application "/Install40" is not the container of the application "/Install40/Web", delete "/Install40" won't help to delete "/Install40/web". This is different with
IIS6.0, you can check the following artile for detailed information:
Understanding Sites, Applications, and Virtual Directories on IIS 7
As far as I know, there is no switch can be turned on to delete both of them. I'll report this issue. At this moment, you'll need to manually or programmatically delete "/Install40/web". Thanks.
Please mark the replies as answers if they help or unmark if not.
Feedback to us
Deleting the parent application via IIS Manager leaves the child applications in the IIS's applicationHost.config
(for others reading this)
Leaving only a script to find and remove them.
Or to use (in 7.5) IIS'sConfiguration Editor to remove the entries. Therein, you must be sure to remove all elements that have the path of your child application(s) including virtual directories
If you then wish to add that same Application back, either by script or IIS Manager, you will get this type of message for the child application:
"An application with this virtual path already exists"
If you edit the config file you must also remove the <location> element tat has that path.
If you use a script then a ADSI object can be used to remove all references to it e.g
vDirName = "Install40"
set IISOBject = GetObject("IIS://localhost/W3SVC/1/Root","")
For Each objItem in IISOBject
if(objItem.Name = vDirName) then
Wscript.Echo "Deleting " & objItem.Name
IISOBject.Delete "IIsWebVirtualDir", objItem.Name
end if
GregJF
4 Posts
Removed nested child folders still in IIS MetaBase
Mar 16, 2012 06:19 AM|LINK
Hi
I develop install scripts for IIS.
Now when I deploy a virtual directory with nested(child) virtual directories, it works fine. (using InstallShield)
But I have a problem when I try it re-install it.
After a successfully deploy, I want to fully re-deploy, so I
This removes the deployed parent virtual directory from the IIS Metabase and the all relevant physical folders.
But if I run the script below I can still see the deployed nested virtual directories, but not the parent virtual directory.
If I add the parent virtual directory and nested virtual directories through IIS Manager, Deploy-> Delete Application and Content then run the script below again; then neither parent virtual directory nor nested virtual directories are in the IIS MetaBase.
I want my script to behave like IIS Manager when I add nested set of virtual directories,
It may not be me or my script that removes the deployed nested set of virtual directories via IIS Manager.
So I am obviously missing a property setting somewhere.
What would that property be?
Code:
===========================================================================================================
===========================================================================================================
Regards
GregJFLeo Tang - M...
4161 Posts
Microsoft
Re: Removed nested child folders still in IIS MetaBase
Mar 19, 2012 10:29 AM|LINK
Hi,
Could you please post the install script here?
You can also run MetaBase Explorer to see if the related Metabase paths are deleted. Thanks.
Feedback to us
Develop and promote your apps in Windows Store
GregJF
4 Posts
Re: Removed nested child folders still in IIS MetaBase
Mar 19, 2012 10:30 PM|LINK
Leo
I refer you to next post I madeRegards
Greg Frazer
GregJF
4 Posts
Re: Removed nested child folders still in IIS MetaBase
Mar 20, 2012 05:18 AM|LINK
Leo
Below are the main functions for creating the IIS applications written in VBScript and using WMI and GetObject("winmgmts:root\WebAdministration")
still does not remove the nest child: /Install40/Web
If we look at the IIS 7.5's applicationHost.config after we run the install, it looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.applicationHost>
<sites>
<site name="Default Web Site" id="1" serverAutoStart="true">
<!-- cut down -->
<application path="/Install40" applicationPool="MyCompanyAppPoolV4">
<virtualDirectory path="/" physicalPath="C:\inetpub\wwwroot\Install40" />
</application>
<application path="/Install40/Web" applicationPool="MyCompanyAppPoolV4">
<virtualDirectory path="/" physicalPath="C:\inetpub\wwwroot\Install40\Web" />
</application>
</site>
</sites>
</system.applicationHost>
</configuration>
Then after Deploy->Delete Application and Content in IIS Manager
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.applicationHost>
<sites>
<site name="Default Web Site" id="1" serverAutoStart="true">
<!-- cut down -->
<application path="/Install40/Web" applicationPool="MyCompanyAppPoolV4">
<virtualDirectory path="/" physicalPath="C:\inetpub\wwwroot\Install40\Web" />
</application>
</site>
</sites>
</system.applicationHost>
</configuration>
/Install40/Web is still there!!!
For this post Assume that the IIS version is 7.5 ( ours is)
Regards
Greg Frazer
//The script code:
webite = "Default Web Site"
vDir = "Install40"
TARGETDIR = "C:\inetpub\wwwroot\" & vDir
vDir = "/" & vDir
'//configure IIS for the application
nResult = CreateIISApp(webite, vDir, TARGETDIR, vDir)
Wscript.Echo "nResult= " & nResult
'// Do the same for the Web
nResult = CreateIISApp(webite, vDir & "/Web", TARGETDIR & "\Web", "Web")
Wscript.Echo "nResult= " & nResult
function CreateIISApp(sWebSite, sVirDirName, sFolder, sFriendlyName)
dim sVersions(3)
dim sThisVersion
dim sScriptMaps
dim sPoolName
dim nResult, n1, n2
dim oRootDir, oWebSite, oVirDir, oScriptMaps, oThisScriptMap
Err.Clear
'//Check to see if the website exists.
nResult = CheckWebSite(sWebSite, oWebSite)
if nResult <> 0 then
CreateIISApp = nResult
exit function
end if
'//Check to see if the application pool exists. Create it if necessary.
nResult = CheckAppPool(sPoolName,sFriendlyName)
if nResult <> 0 then
CreateIISApp = nResult
exit function
end if
nResult = 0
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")
' Use InstancesOf to retrieve the applications.
Set oApps = oWebAdmin.InstancesOf("Application")
' Iterate through the applications.
For Each oApp In oApps
if(sVirDirName = oApp.Path) then
Wscript.Echo sVirDirName
CreateIISApp = 1
exit function
end if
Next
' Create the new application
oWebAdmin.Get("Application").Create sVirDirName, sWebSite, sFolder
' Iterate through the applications.
Set oApps = oWebAdmin.InstancesOf("Application")
For Each oApp In oApps
if(sVirDirName = oApp.Path) then
Wscript.Echo " inside: " & sVirDirName
oApp.ApplicationPool = sPoolName
oApp.Put_
' create the physical path if it does not exist
set filesys = CreateObject("Scripting.FileSystemObject")
If Not filesys.FolderExists(sFolder) Then
Set newfolder = filesys.CreateFolder(sFolder)
Wscript.Echo "newfolder: " & newfolder
End If
CreateIISApp = 6
exit function
end if
Next
CreateIISApp = 0
exit function
end function
'//---------------------------------------------------------------------------
'// CheckAppPool
'//
'// Tries to get the pool to be used by the IIS application. Creates it if one doesn't already exist
'//
'//---------------------------------------------------------------------------
function CheckAppPool(sPoolName,sFriendlyName)
dim oAppPoolList
dim oAppPool
dim varEnum
dim nResult
on error resume next
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")
'//IIS application pools are only supported from version 6 on Windows 2003. Therefore just leave.
'//if (IISRTGetIISVersion(IIS_GET_VERSION_MAJOR) < 6) then
'///NOTE For this post assume only ISS 7.0 and greater
'// return 0;
'//endif;
sPoolName = "MyCompanyAppPoolV4"
' Retrieve the default App Pool.
getParam = "ApplicationPool.Name='" & sPoolName & "'"
Set oAppPool = oWebAdmin.Get(getParam)
if(not oAppPool is nothing) then
CheckAppPool = 0
exit function
end if
'//does exist so create it
oWebAdmin.Get("ApplicationPool").Create(sPoolName)
Set oAppPool = oWebAdmin.Get(getParam)
if oAppPool is NOTHING then
'//Failed to create AppPool
CheckAppPool = 12
exit function
end if
oAppPool.Put_
'//Created IIS Application Pool
CheckAppPool = 0
end function
'//---------------------------------------------------------------------------
'// CheckWebSite
'//
'// Search the computer for a specific website and return the web site object
'//
'//---------------------------------------------------------------------------
function CheckWebSite(sWebSite, oWebSite)
dim oWebSvc
dim varEnum
on error resume next
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")
if (oWebAdmin is nothing) then
'// Failed to find IIS Object
CheckWebSite = 9
exit function
end if
' Retrieve the web site.
getParam = "Site.Name='" & sWebSite & "'"
Set webSite = oWebAdmin.Get(getParam)
if(not webSite is nothing) then
set oWebSite = webSite
CheckWebSite = 0
exit function
end if
'// We should go onto create the website, but for now return an error stating that the website couldn't be found
CheckWebSite = 10
end function
Leo Tang - M...
4161 Posts
Microsoft
Re: Removed nested child folders still in IIS MetaBase
Mar 20, 2012 09:03 AM|LINK
Hi,
In this case, the script create two applications instead of two virtual directories. As the application "/Install40" is not the container of the application "/Install40/Web", delete "/Install40" won't help to delete "/Install40/web". This is different with IIS6.0, you can check the following artile for detailed information:
Understanding Sites, Applications, and Virtual Directories on IIS 7
http://learn.iis.net/page.aspx/150/understanding-sites-applications-and-virtual-directories-on-iis/
As far as I know, there is no switch can be turned on to delete both of them. I'll report this issue. At this moment, you'll need to manually or programmatically delete "/Install40/web". Thanks.
Feedback to us
Develop and promote your apps in Windows Store
GregJF
4 Posts
Re: Removed nested child folders still in IIS MetaBase
Mar 20, 2012 10:26 PM|LINK
Leo
Yes that has been my experience.
It is a little worst though.
Deleting the parent application via IIS Manager leaves the child applications in the IIS's applicationHost.config
(for others reading this)
Leaving only a script to find and remove them.
Or to use (in 7.5) IIS'sConfiguration Editor to remove the entries. Therein, you must be sure to remove all elements that have the path of your child application(s) including virtual directories
If you then wish to add that same Application back, either by script or IIS Manager, you will get this type of message for the child application:
"An application with this virtual path already exists"If you edit the config file you must also remove the <location> element tat has that path.
If you use a script then a ADSI object can be used to remove all references to it e.g
=============================================================
vDirName = "Install40"
set IISOBject = GetObject("IIS://localhost/W3SVC/1/Root","")
For Each objItem in IISOBject
if(objItem.Name = vDirName) then
Wscript.Echo "Deleting " & objItem.Name
IISOBject.Delete "IIsWebVirtualDir", objItem.Name
end if
Next
===============================================================
Regards
GregJF