By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,161 Members | 2,002 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,161 IT Pros & Developers. It's quick & easy.

How to stop an Application Pool in IIS 6.0 in c#?

P: n/a
I'm trying to write a custom installation engine to plug into our
existing build system. Some things I'm trying to do are,
Create/Delete/Start/Stop Application Pools, Web Sites, and Virtual
Directories.

At this point I'd be happy if someone can provide a sample of how to
Stop an application pool. Or point me in the right direction.

Thanks!

Mike
Sep 7 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hello M,

what's your "application pools" ?
How do u create them?

Not so clear for me

MCI'm trying to write a custom installation engine to plug into our
MCexisting build system. Some things I'm trying to do are,
MCCreate/Delete/Start/Stop Application Pools, Web Sites, and Virtual
MCDirectories.
MC>
MCAt this point I'd be happy if someone can provide a sample of how to
MCStop an application pool. Or point me in the right direction.
MC>
MCThanks!
MC>
MCMike
MC>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Sep 7 '06 #2

P: n/a
In IIS 6.0 I manually create seperate application pools for each web
site I host on our servers. This way each web site runs in it's own
memory space and can be recycled independant of the other web sites.

Steps to Create:
1. Open compmgmt.msc
2. Expand Services and Applications
3. Expand Internet Information Services
4. Expand Application Pools (Windows 2003 Server)
5. New -Application Pool...
6. Give it a name, click OK.
7. Open properties to a web site
8. Click Home Directory
9. Change Application pool to your new pool name. click Ok.


Michael Nemtsev wrote:
Hello M,

what's your "application pools" ?
How do u create them?

Not so clear for me

MCI'm trying to write a custom installation engine to plug into our
MCexisting build system. Some things I'm trying to do are,
MCCreate/Delete/Start/Stop Application Pools, Web Sites, and Virtual
MCDirectories.
MCMCAt this point I'd be happy if someone can provide a sample of
how to
MCStop an application pool. Or point me in the right direction.
MCMCThanks!
MCMCMike
MC---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do
not cease to be insipid." (c) Friedrich Nietzsche

Sep 7 '06 #3

P: n/a
Hello M,

AFAIK, pools are created by IIS for each new virtual folder, u need only
to point that this folder works with that pool
ADSI helps u to manage IIS pools, but ADSI is unmanaged http://msdn.microsoft.com/library/de...5344a7b851.asp

To stop pool use IISApplicationPool::Stop http://msdn.microsoft.com/library/de...b2de05644c.asp

in this case u need to make your calls via interop

MCIn IIS 6.0 I manually create seperate application pools for each web
MCsite I host on our servers. This way each web site runs in it's own
MCmemory space and can be recycled independant of the other web sites.
MC>
MCSteps to Create:
MC1. Open compmgmt.msc
MC2. Expand Services and Applications
MC3. Expand Internet Information Services
MC4. Expand Application Pools (Windows 2003 Server)
MC5. New -Application Pool...
MC6. Give it a name, click OK.
MC7. Open properties to a web site
MC8. Click Home Directory
MC9. Change Application pool to your new pool name. click Ok.
MCMichael Nemtsev wrote:
MC>
>Hello M,

what's your "application pools" ?
How do u create them?
Not so clear for me

MCI'm trying to write a custom installation engine to plug into our
MCexisting build system. Some things I'm trying to do are,
MCCreate/Delete/Start/Stop Application Pools, Web Sites, and
Virtual
MCDirectories.
MCMCAt this point I'd be happy if someone can provide a sample of
how to
MCStop an application pool. Or point me in the right direction.
MCMCThanks!
MCMCMike
MC---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour
"At times one remains faithful to a cause only because its opponents
do not cease to be insipid." (c) Friedrich Nietzsche
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Sep 7 '06 #4

P: n/a
Thanks but C++ isn't my thing! :)

I did find a solution:
const string WebServerSchema = "IIsApplicationPools"; // Case Sensitive
string ServerName = "LocalHost";
DirectoryEntry W3SVC = new DirectoryEntry("IIS://" +
ServerName + "/w3svc", "", "");

foreach (DirectoryEntry Site in W3SVC.Children)
{
Console.WriteLine(Site.SchemaClassName);
if (Site.SchemaClassName == WebServerSchema)
foreach (DirectoryEntry child in Site.Children)
{
Console.WriteLine(child.Parent + ": " +
child.Name);
if (child.Name == appPoolName)
{
PropertyCollection appPoolProps =
child.Properties;
foreach (string PropName in
appPoolProps.PropertyNames)
{
Console.WriteLine("Application
Pool: {0} - {1}", PropName, appPoolProps[PropName].Value);
}
appPoolProps["AppPoolCommand"].Value =
AppPoolCommandEnum.stop; // 2==stop, 1==start
child.CommitChanges();
}
}
Console.WriteLine(Site.Name + " - " +
Site.Properties["ServerComment"].Value.ToString());
}

This is working for me.

Thanks.

Michael Nemtsev wrote:
Hello M,

AFAIK, pools are created by IIS for each new virtual folder, u need only
to point that this folder works with that pool
ADSI helps u to manage IIS pools, but ADSI is unmanaged
http://msdn.microsoft.com/library/de...5344a7b851.asp
To stop pool use IISApplicationPool::Stop
http://msdn.microsoft.com/library/de...b2de05644c.asp
in this case u need to make your calls via interop

MCIn IIS 6.0 I manually create seperate application pools for each web
MCsite I host on our servers. This way each web site runs in it's own
MCmemory space and can be recycled independant of the other web sites.
MCMCSteps to Create:
MC1. Open compmgmt.msc
MC2. Expand Services and Applications
MC3. Expand Internet Information Services
MC4. Expand Application Pools (Windows 2003 Server)
MC5. New -Application Pool...
MC6. Give it a name, click OK.
MC7. Open properties to a web site
MC8. Click Home Directory
MC9. Change Application pool to your new pool name. click Ok.
MCMichael Nemtsev wrote:
MC>
>>Hello M,

what's your "application pools" ?
How do u create them?
Not so clear for me

MCI'm trying to write a custom installation engine to plug into our
MCexisting build system. Some things I'm trying to do are,
MCCreate/Delete/Start/Stop Application Pools, Web Sites, and
Virtual
MCDirectories.
MCMCAt this point I'd be happy if someone can provide a sample of
how to
MCStop an application pool. Or point me in the right direction.
MCMCThanks!
MCMCMike
MC---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour
"At times one remains faithful to a cause only because its opponents
do not cease to be insipid." (c) Friedrich Nietzsche
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do
not cease to be insipid." (c) Friedrich Nietzsche

Sep 7 '06 #5

P: n/a
Thanks but C++ isn't my thing! :)

I did find a solution:
const string WebServerSchema = "IIsApplicationPools"; // Case Sensitive
string ServerName = "LocalHost";
DirectoryEntry W3SVC = new DirectoryEntry("IIS://" +
ServerName + "/w3svc", "", "");

foreach (DirectoryEntry Site in W3SVC.Children)
{
Console.WriteLine(Site.SchemaClassName);
if (Site.SchemaClassName == WebServerSchema)
foreach (DirectoryEntry child in Site.Children)
{
Console.WriteLine(child.Parent + ": " +
child.Name);
if (child.Name == appPoolName)
{
PropertyCollection appPoolProps =
child.Properties;
foreach (string PropName in
appPoolProps.PropertyNames)
{
Console.WriteLine("Application
Pool: {0} - {1}", PropName, appPoolProps[PropName].Value);
}
appPoolProps["AppPoolCommand"].Value =
AppPoolCommandEnum.stop; // 2==stop, 1==start
child.CommitChanges();
}
}
Console.WriteLine(Site.Name + " - " +
Site.Properties["ServerComment"].Value.ToString());
}

This is working for me.

Thanks.

Michael Nemtsev wrote:
Hello M,

AFAIK, pools are created by IIS for each new virtual folder, u need only
to point that this folder works with that pool
ADSI helps u to manage IIS pools, but ADSI is unmanaged
http://msdn.microsoft.com/library/de...5344a7b851.asp
To stop pool use IISApplicationPool::Stop
http://msdn.microsoft.com/library/de...b2de05644c.asp
in this case u need to make your calls via interop

MCIn IIS 6.0 I manually create seperate application pools for each web
MCsite I host on our servers. This way each web site runs in it's own
MCmemory space and can be recycled independant of the other web sites.
MCMCSteps to Create:
MC1. Open compmgmt.msc
MC2. Expand Services and Applications
MC3. Expand Internet Information Services
MC4. Expand Application Pools (Windows 2003 Server)
MC5. New -Application Pool...
MC6. Give it a name, click OK.
MC7. Open properties to a web site
MC8. Click Home Directory
MC9. Change Application pool to your new pool name. click Ok.
MCMichael Nemtsev wrote:
MC>
>>Hello M,

what's your "application pools" ?
How do u create them?
Not so clear for me

MCI'm trying to write a custom installation engine to plug into our
MCexisting build system. Some things I'm trying to do are,
MCCreate/Delete/Start/Stop Application Pools, Web Sites, and
Virtual
MCDirectories.
MCMCAt this point I'd be happy if someone can provide a sample of
how to
MCStop an application pool. Or point me in the right direction.
MCMCThanks!
MCMCMike
MC---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour
"At times one remains faithful to a cause only because its opponents
do not cease to be insipid." (c) Friedrich Nietzsche
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do
not cease to be insipid." (c) Friedrich Nietzsche

Sep 7 '06 #6

P: n/a

"M Craig" <mc******@newsgroups.nospamwrote in message
news:uK**************@TK2MSFTNGP05.phx.gbl...
| I'm trying to write a custom installation engine to plug into our
| existing build system. Some things I'm trying to do are,
| Create/Delete/Start/Stop Application Pools, Web Sites, and Virtual
| Directories.
|
| At this point I'd be happy if someone can provide a sample of how to
| Stop an application pool. Or point me in the right direction.
|
| Thanks!
|
| Mike
Using System.Management and WMI is one option using scripting is another.

StopAppPool("admin", "adminPwd", "remServer", "W3SVC/AppPools/MyAppPool");

....

static void StopAppPool(string ConnectionUser, string ConnectionPassword,
string Machine, string appPool )
{
ConnectionOptions co = new ConnectionOptions();
co.Username = ConnectionUser;
co.Password = ConnectionPassword;
co.Impersonation = ImpersonationLevel.Impersonate;
co.Authentication = AuthenticationLevel.PacketPrivacy;
string objPath = "IISApplicationPool.Name='" + appPool + "'"; // watch the
single quotes!!

ManagementScope scope = new ManagementScope(@"\\" + Machine +
@"\root\MicrosoftIISV2", co);

using(ManagementObject mc = new ManagementObject(objPath))
{
mc.Scope = scope;
mc.InvokeMethod("Stop", null, null);
}
}

Please consult:
http://msdn.microsoft.com/library/de...43ffc70e16.asp

for more details.
Sep 7 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.