Lister les pools d'application sous IIS6.0
Bonjour à tous.
Je souhaite réaliser un programme qui m'afficherai la liste des pools d'applications tournant sur un serveur.
Le serveur fonctionne sous Windows 2003 serveur le framework 3.5 y est installé et IIS et en version 6.0.
Pour faire mon programme j'utilise la classe
Code:
System.DirectoryServices.DirectoryEntry
Mon problème et que je n'arrive pas à obtenir le nom des pools tournants sur la machine,en effet j'obtiens au mieux le chemin du pool(comprenant son PID)
Je sais q'un scripts .vbs de Windows affiche la correspondance entre le PID et le nom d'un pool d'application.
Ma seul solution serait juste de lancer ce script et d'en récupérer la sortie ?
Edit(16h02): L'éxécution du script (c:\WINDOWS\System32\issapp.vbs) en question me renvoit une erreur:aucun résultats :s alors et mes pools sont bien indiqués comme actifs.
PS:
Voici le code de mon programme de test:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.DirectoryServices;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Collections;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
EnumerateApplicationsInPool("IIS://localhost/W3SVC/AppPools/DefaultAppPool", this.listBox1);
}
static void EnumerateApplicationsInPool(string metabasePath, ListBox li2)
{
// metabasePath is of the form "IIS://<servername>/W3SVC/AppPools/<poolName>"
// for example "IIS://localhost/W3SVC/AppPools/DefaultAppPool"
//Console.WriteLine("\nEnumerating applications for the {0} pool:", metabasePath);
li2.Items.Add("\nEnumerating applications for the " + metabasePath + " pool:");
try
{
DirectoryEntry entry = new DirectoryEntry(metabasePath);
if ("IIsApplicationPool" == entry.SchemaClassName)
{
object[] param;
param = (object[])entry.Invoke("EnumAppsInPool", null);
foreach (string s in param)
{
li2.Items.Add("\n");
li2.Items.Add("Guid:" + entry.Guid +"");
li2.Items.Add("Path:"+entry.Path+"");
li2.Items.Add("ClassName:"+entry.SchemaClassName+"");
li2.Items.Add("NativeGuid:"+entry.NativeGuid+"");
li2.Items.Add("NativeObject:"+entry.NativeObject+"");
li2.Items.Add("Name:"+entry.Name+"");
li2.Items.Add("Properties:" + entry.Properties + "");
li2.Items.Add(s);
li2.Items.Add("\n");
}
//Console.WriteLine(" {0}", s);
//Console.WriteLine(" Done.");
li2.Items.Add(" Done.");
}
else
//Console.WriteLine(" Failed in EnumerateApplicationsInPool; {0} is not an app pool", metabasePath);
li2.Items.Add(" Failed in EnumerateApplicationsInPool; " + metabasePath + " is not an app pool");
}
catch (Exception ex)
{
//Console.WriteLine("Failed in EnumerateApplicationsInPool with the following exception: \n{0}", ex);
li2.Items.Add("Failed in EnumerateApplicationsInPool with the following exception: \n"+ex+"");
}
}
}
} |