<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Tags/Programmatically on Emad Alashi</title>
    <link>https://emadashi.com/tags/programmatically/</link>
    <description>Recent content in Tags/Programmatically on Emad Alashi</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Tue, 11 Sep 2012 07:10:54 +0000</lastBuildDate>
    <atom:link href="https://emadashi.com/tags/programmatically/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Microsoft.Web.Administration for IIS</title>
      <link>https://emadashi.com/2012/09/microsoft-web-administration-for-iis/</link>
      <pubDate>Tue, 11 Sep 2012 07:10:54 +0000</pubDate>
      <guid>https://emadashi.com/2012/09/microsoft-web-administration-for-iis/</guid>
      <description>&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: In addition to this post, you can check as well the valuable &lt;a href=&#34;http://stuartcullinan.blogspot.com.au/2011/04/some-tips-on-using-microsoftwebadminist.html&#34;&gt;post&lt;/a&gt; of Stuart Cullinans&amp;rsquo;s.&lt;/p&gt;
&lt;p&gt;One of the recent projects I worked on involved managing IIS programmatically, and I found the proper tool for it, meet “&lt;a href=&#34;http://msdn.microsoft.com/en-us/library/microsoft.web.administration%28v=vs.90%29.aspx&#34;&gt;Microsoft.Web.Administration&lt;/a&gt;”.&lt;/p&gt;
&lt;p&gt;You can read about this library&amp;rsquo;s purpose in its own page above; what I will list here are three points I noticed while dealing with the library:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;I couldn’t find where to download, or install the library from, it appeared to be residing in “&lt;strong&gt;C:\Windows\SysWOW64\inetsrv\Microsoft.Web.Administration.dll&lt;/strong&gt;” and yes my OS is 64-bit I am not sure where you can find that on a 32-bit machine&lt;/li&gt;
&lt;li&gt;The main class &lt;strong&gt;ServerManager&lt;/strong&gt; reads data the moment it’s created only, it will &lt;strong&gt;NOT&lt;/strong&gt; maintain a valid state after the initial read; for example, consider the following snippet:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-csharp&#34; data-lang=&#34;csharp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;static&lt;/span&gt; WorkerProcess currentWP;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;static&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;void&lt;/span&gt; Main(&lt;span style=&#34;color:#66d9ef&#34;&gt;string&lt;/span&gt;[] args)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    currentWP = &lt;span style=&#34;color:#66d9ef&#34;&gt;new&lt;/span&gt; ServerManager().ApplicationPools[&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;].WorkerProcesses[&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;];
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;while&lt;/span&gt; (!Console.ReadLine().Equals(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;quit&amp;#34;&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        Console.WriteLine(currentWP.ProcessId.ToString());
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This code snippet will get the first WorkerProcess of the first Application Pool in the local IIS. Run the code, enter bogus input just to make sure the loop works, and you will find on the Console the W3WP Process Id displayed (e.g. 4295).&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
