Click here to Skip to main content
13,346,397 members (62,941 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


2 bookmarked
Posted 21 Feb 2012

Recycling IIS Apppools .

, 21 Feb 2012
Rate this:
Please Sign up or sign in to vote.

This is Test Application which can be used to recycle the IIS App Pools of the server. In this app I have given only one server but you can give any no of servers you want just add the buttons and copy the code of the button "button_Server_Click" to the other button code's. Also you can add any no. of apppools you want.

Using the code

This is a test Application .In this Application I have used WMIC Code to recycle the AppPools of the server .The code to recycle the Apppool is written in button click event "button_Server_Click"

 string command = String.Empty;//string variable..
//Passing WMIC code to command variable.For recycling more than one apppool declare multiple string variables and pass WMIC code like mentioned below.
command = "wmic /namespace:" + "\"\\\\root/MicrosoftIISv2\"" + " /node:" + " \"Your_             Server_Name\"  " + "path IISApplicationPool where (name like '%Your_IISAppool1%') call recycle";
           ExecuteCmd cmd = new ExecuteCmd();//declaring object of class ExecuteCmd
           cmd.ExecuteCommandAsync(command);//Passing string variable containing WMIC code to method ExecuteCommandAsync declared in class ExecuteCmd.
//This"ExecuteCommandAsync" method is used  to execute the WMIC Command. it is in the class "ExecuteCmd" 
public void ExecuteCommandAsync(string command)
                //Asynchronously start the Thread to process the Execute command request.
                Thread objThread = new Thread(new ParameterizedThreadStart(ExecuteCommandSync));
                //Make the thread as background thread.
                objThread.IsBackground = true;
                //Set the Priority of the thread.
                objThread.Priority = ThreadPriority.AboveNormal;
                //Start the thread.
            catch (ThreadStartException objException)
                // Log the exception
            catch (ThreadAbortException objException)
                // Log the exception

            catch (Exception objException)
                // Log the exception

Here the main code is "wmic /namespace:" + "\"\\\\root/MicrosoftIISv2\"" + " /node:" + " \"%Your_ Server_Name%\" " + "path IISApplicationPool where (name like '%Your_IISAppool1%') call recycle";"

In"% Your_Server_Name%" :- Give the name of the server whose apppool you want to recycle.

In" %Your_IISAppool1%" :- Give the name of IIS apppool of the server you want to recycle.

Point to be noted:- All the server should be in same network.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer Wipro Infotech
India India
I am working in Wipro as an software engineer .I am working in .net domain . I am right now in Server Configuration Team but had some handson in developing windows Application and crystal reports.
Developing new Application provides new challenges which has to be dealt with outmost courage similarly to 300 style.
I have come across lot difficulties in developing these applications so through Code Project I want to put forward my experiences to other geeks.
Hope my experiences will prove helpfull to you Guys........

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180111.1 | Last Updated 21 Feb 2012
Article Copyright 2012 by yudi19872001
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid