Batch to Logging Worker Process Recycling Events in IIS 6.

I want to log Worker Process Recycling Events in IIS 6.0 (IIS 6.0) , but ther is no UI for this.
I’ve created batch file and decided to post it here, because current instructions have a few typos.
You should modify value of AppPoolName as appropriate.


:rem IISLoggingWorkerProcessRecycling.bat
:rem from http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/87892589-4eda-4003-b4ac-3879eac4bf48.mspx?mfr=true
set EnableEvent=true
set AppPoolName=ASP.NET v2.0
%systemDRIVE%
cd %systemDRIVE%inetpubadminscripts
cscript adsutil.vbs set “w3svc/AppPools/%AppPoolName%/AppPoolRecycleTime” %EnableEvent%
cscript adsutil.vbs set “w3svc/AppPools/%AppPoolName%/AppPoolRecycleRequests” %EnableEvent%
cscript adsutil.vbs set “w3svc/AppPools/%AppPoolName%/AppPoolRecycleSchedule” %EnableEvent%
cscript adsutil.vbs set “w3svc/AppPools/%AppPoolName%/AppPoolRecycleMemory” %EnableEvent%
cscript adsutil.vbs set “w3svc/AppPools/%AppPoolName%/AppPoolRecycleIsapiUnhealthy” %EnableEvent%
cscript adsutil.vbs set “w3svc/AppPools/%AppPoolName%/AppPoolRecycleOnDemand” %EnableEvent%
cscript adsutil.vbs set “w3svc/AppPools/%AppPoolName%/AppPoolRecycleConfigChange” %EnableEvent%
cscript adsutil.vbs set “w3svc/AppPools/%AppPoolName%/AppPoolRecyclePrivateMemory” %EnableEvent%


 

Intermittent execution of custom action for installation of product upgrade.

I’ve recently posted Custom action condition to run for a new or upgraded product., but I found that the custom action doesn’t always call executable.
 I removed any custom action conditions, but it still doesn’t always produced the same result
I had to install ORCA, and found that my Custom Action has source _5C6AF63299974A76AD78EA44FCE751A6 (reference to MSIAssembly table ) and type 1042(Custom Action Type 18 + msidbCustomActionTypeInScript 1024)
The CustomAction guid key has entry in InstallExecuteSequence table with condition $C__5C6AF63299974A76AD78EA44FCE751A6>2  and sequence 5999.
According to Conditional Statement Syntax. $component-action >2 means Action state of the component.is installed locally or run from the source.
It means that sometimes installer doesn’t recognize that a component is installed( I still don’t understand the pattern??). 
Actually according to Custom Action Tutorial  Custom Action runs only when the component is being added(or deleted).

Custom action condition to run for a new or upgraded product.

I have a custom action condition (in Visual Studio Web Setup Project) that I want  to run for installation of a new or upgraded product. I do not want to run it on repair (and also during uninstall).


First of all I tried “Not Installed” condition. But it doesn’t work for version upgrade. I’ve tried


Not Remove=”ALL” but it also doesn’t work for version upgrade( it seems that deleting previous version set the property Remove=”ALL”)


I’ve tried UPGRADINGPRODUCTCODE , but it is set for the previous version, not for the version being installed.


The article http://www.rsdn.ru/article/install/wininstaller2.xml (sorry, in Russian only) suggests to use IS_MAJOR_UPGRADE ,but the property is applicable for InstalledShield only.


Finally I found combination that is working:


(Not Installed) OR PREVIOUSVERSIONSINSTALLED
Note that brackets are important to evaluate NOT first and condition is case-sensitive).


PREVIOUSVERSIONSINSTALLED is not documented property, I found it when reading msi log and in a few posts(e.g. here: “If the search at the start of the install detects
an older version, it creates the PREVIOUSVERSIONSINSTALLED property,
case-sensitive.“ ).


NOTE: I found that custom action with condition
(Not Installed) OR PREVIOUSVERSIONSINSTALLED works on my development machine, but it was not invoked on my deployment machine until I changed target virtual directory. Mistery ???

How to open web.config file from custom action installer class, located in DLL.


One of the readers of the my post “Using VS 2005 Web Setup Project with custom actions” asked how to pick web.config file. that is actually part of the web project, from custom action installer class located in a separate DLL.


 With an assumption that DLL with installer class located in the BIN folder of the web project , you can do the following:


Dim asm As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
Dim sConfigFileName As String FSHelperLib.AppSettingsHelper.GetConfigFileName(asm)


where  


        public static string GetConfigFileName(Assembly ExecutingAssembly)


        {


            string sPath = “”;


            { //root folder one level up from bin


                sPath = SystemHelper.GetWebRootFolder(ExecutingAssembly);


                sPath = sPath + @”web.config”;


}


            if (!File.Exists(sPath))


            {


                throw new FileNotFoundException(“Missing config file “ + sPath);


            }


            return sPath;


        }


 See also My SystemHelper class for GetWebRootFolder definition.



 

Set a property for ISSWebFile in subfolder.

Recently I posted class that I am using to Programmatically set IIS Authentication for a page. Later I found that initial implementation almost never worked because  files in subfolders usually do not have explicit entries in the metabase, but inherit all properties from the parent. I’ve added code to create metabase entry (similar to this). But if the file is in subfolder, not in the virtual directory, adding the SchemaClassNames=“IIsWebFile” doesn’t work (see discussion Creating Virtual Directories using DirectoryEntry – HRESULT: 0x8000500F).


I’ve spend a lot of time triying to workaround this and finally ADSUTIL gave me a hint:
WARNING: The Object Type of this object was not specified or was specified as IIsObject.
This means that you will not be able to set or get properties on the object until the KeyType property is set.


The solution is to create object with SchemaClassName = “IIsObject” and then set
entry.Properties[“keyType“].Value = “IIsWebFile”;
I’ve updated my class to fix the problem.

Configuration.Save Method parameters combination

I’ve reported to MS that documentation of Configuration.Save Method (ConfigurationSaveMode, Boolean)   is not detailed enough and they provided the clarification:

The ConfigurationSaveMode parameter can have one of the following values: 













Full


Causes all properties to be written to the configuration file. This is useful mostly for creating information configuration files or moving configuration values from one machine to another. 


Minimal


Causes only properties that differ from inherited values to be written to the configuration file. 


 Modified


Causes only modified properties to be written to the configuration file, even when the value is the same as the inherited value


 The additional forceSaveAll is sometimes needed to override the behavior as defined by the ConfigurationSaveMode and force all the configuration properties to be saved. This is a combination of inherited and locally defined or changed properties.

Using Configuration.Section to access subsection

I have a section in Web.Config:


  <applicationSettings>


    <FSBsnsCsLib.Properties.Settings>



   </</FSBsnsCsLib.Properties.Settings>


 </</applicationSettings>


I’ve tried to access inner section using shortcut “Section/Subsection“


string sSectionName=”applicationSettings/FSBusinessLib.My.MySettings”;
System.Configuration.ClientSettingsSection sectSettings = (ClientSettingsSection)config.Sections[sSectionName];


but it returned null.


The correct way is the following:


const string cnstApplicationSection = applicationSettings;
ConfigurationSectionGroup grpApplicationSection = config.SectionGroups[cnstApplicationSection];
string sSectionName=”FSBusinessLib.My.MySettings”;
System.Configuration.ClientSettingsSection sectSettings = grpApplicationSection .Sections[sSectionName];

This approach is used in my ConfigurationHelper class