fabian09
fabian09

Reputation: 131

How to get the property "Start Mode" of a running AppPool

i'm writing a peace of code in what i check specific properties of a running AppPool. So far i got "Enable32BitAppOnWin64" "IdentityType" "UserName" and "Password". Now, i try to get the property "Start Mode". But i'm not able to find this property on any level. Does someone know how to get this one?

namespace Automated_Tests { class AppPoolUser {

    Output_Handler OutputHandler = new Output_Handler();

    public string ServiceUser { get; set; } = ".\\Administrator";
    public string ServiceUserPassword { get; set; } = "admin";

    public void ExecuteAppPoolUserCheck()
    {
        CheckExistingApplicationPool("Platform Services (RO) App Pool", true);
        CheckExistingApplicationPool("Platform Services App Pool", true);
        CheckExistingApplicationPool("Processes App Pool", false);
        CheckExistingApplicationPool("Settings App Pool", true);
        CheckExistingApplicationPool("Web App Pool", true);
    }

    private void CheckExistingApplicationPool(string applicationPoolName, bool is64Bit)
    {
        ApplicationPool applicationPool = GetApplicationPool(applicationPoolName);

        if (applicationPool != null)
        {
            if (is64Bit)
            { CheckAppPoolBitnessfor64BitAppPool(applicationPool); }
            else { CheckAppPoolBitnessfor32BitAppPool(applicationPool); }
        }
        else
        {
            return;
        }
        CheckApplicationPoolUser(applicationPool);
        CheckApplicationPoolStartMode(applicationPool);
    }

    private ApplicationPool GetApplicationPool(string appPoolName)
    {
        var serverManager = new ServerManager();

        try
        {
            ApplicationPool appPool = serverManager.ApplicationPools[appPoolName];
            return appPool;
        }
        catch (Exception ex)
        {

            logger.Debug(ex, "Application Pool " + serverManager.ApplicationPools[appPoolName] + " does not exist");
            return null;
        }

    }

    private void CheckAppPoolBitnessfor32BitAppPool(ApplicationPool applicationPool)
    {
        //boolean == true 
        if (applicationPool.Enable32BitAppOnWin64)
        {
            OutputHandler.ColorCMDOutput("The AppPoolBitness 32Bit is correctly set for " + applicationPool.Name, ConsoleColor.Green);
        }
        else
        {
            OutputHandler.ColorCMDOutput("The AppPoolBitness 32Bit is NOT correctly set for " + applicationPool.Name, ConsoleColor.Red);
            OutputHandler.AppendDataToFile(@"C:\Users\Public\TestFolder\Buglist.txt", "The AppPoolBitness 32BIT is NOT correctly set for " + applicationPool.Name);
        }
    }

    private void CheckAppPoolBitnessfor64BitAppPool(ApplicationPool applicationPool)
    {
        //boolean == false 
        if (!applicationPool.Enable32BitAppOnWin64)
        {
            OutputHandler.ColorCMDOutput("The AppPoolBitness 64BIT is correctly set for " + applicationPool.Name, ConsoleColor.Green);
        }
        else
        {
            OutputHandler.ColorCMDOutput("The AppPoolBitness 64BIT is NOT correctly set for " + applicationPool.Name, ConsoleColor.Red);
            OutputHandler.AppendDataToFile(@"C:\Users\Public\TestFolder\Buglist.txt", "The AppPoolBitness 64BIT is NOT correctly set for " + applicationPool.Name);
        }
    }

    private void CheckApplicationPoolUser(ApplicationPool applicationPool)
    {
        if (applicationPool.ProcessModel.IdentityType != ProcessModelIdentityType.SpecificUser)
        {
            OutputHandler.ColorCMDOutput("The AppPoolIdentitytype \"SpecificUser\" is NOT correctly set for " + applicationPool.Name + ". The currently Set value is \"" + applicationPool.ProcessModel.IdentityType.ToString() + "\"", ConsoleColor.Red);
            OutputHandler.AppendDataToFile(@"C:\Users\Public\TestFolder\Buglist.txt", "The AppPoolIdentitytype \"SpecificUser\" is NOT correctly set for " + applicationPool.Name + ". The currently set value is \"" + applicationPool.ProcessModel.IdentityType.ToString() + "\"");
            return;
        }
        else
        {
            OutputHandler.ColorCMDOutput("The AppPoolIdentitytype \"SpecificUser\" is correctly set for " + applicationPool.Name, ConsoleColor.Green);
        }
        {
            if (applicationPool.ProcessModel.UserName != ServiceUser)
            {
                OutputHandler.ColorCMDOutput("The AppPoolUserame \"Administrator\" is NOT correctly set  for " + applicationPool.Name + ". The currently set value is \"" + applicationPool.ProcessModel.UserName.ToString() + "\"", ConsoleColor.Red);
                OutputHandler.AppendDataToFile(@"C:\Users\Public\TestFolder\Buglist.txt", "The AppPoolUserame \"Administrator\" is NOT correctly set  for " + applicationPool.Name + ". The currently set value is \"" + applicationPool.ProcessModel.UserName.ToString() + "\"");
            }
            else
            {
                OutputHandler.ColorCMDOutput("The AppPoolUserame \"Administrator\" is correctly set for " + applicationPool.Name, ConsoleColor.Green);
            }

            if (applicationPool.ProcessModel.Password != ServiceUserPassword)
            {
                OutputHandler.ColorCMDOutput("The AppPoolPassword \"admin\" is NOT correctly set  for " + applicationPool.Name + ". The currently set value is \"" + applicationPool.ProcessModel.Password.ToString() + "\"", ConsoleColor.Red);
                OutputHandler.AppendDataToFile(@"C:\Users\Public\TestFolder\Buglist.txt", "The AppPoolPassword \"admin\" is NOT correctly set  for " + applicationPool.Name + ". The currently set value is \"" + applicationPool.ProcessModel.Password.ToString() + "\"");
            }
            else
            {
                OutputHandler.ColorCMDOutput("The AppPoolPassword \"admin\" is correctly set for " + applicationPool.Name, ConsoleColor.Green);
            }
        }
    }

    private void CheckApplicationPoolStartMode(ApplicationPool applicationPool)
    {

    }
}

}

Upvotes: 0

Views: 551

Answers (1)

Lex Li
Lex Li

Reputation: 63264

Use .Attributes of ConfigurationElement class (Application class is derived from it) to access such,

https://msdn.microsoft.com/en-us/library/microsoft.web.administration.configurationelement.attributes(v=vs.90).aspx

Upvotes: 1

Related Questions