Using WMI To Query IIS

I need to query IIS using WMI to pull out information about the file extension mappings for the currently executing web. The problem is, I don't have clue one on how to do it, and IMO WMI is a giant undocumented clusterf$@#. Do any of you smart guys have any ideas on how to make this happen? I know there is a fairly simple query to nake it happen, I just can't figure it out.

8 Comments

  • We use the COM interface to the metabase to add extension mappings during our install.

    The code is straight C/C++ and I *think* the Set just becomes a Get for your purposes (we may actually do a get first to see if we need to do the set!)



    If that sounds useful I can dig into the Source tree and pull the code..



    drop me an email, or throw a comment somewhere (your blog or mine)



    And yes, it's a giant clusterf.

  • Would you settle for using ADSI? I can figure out to do it with that easily enough.

  • I'd rather not use COM Interop because it requires the assembly to have full trust. Sounds pretty nifty though. Anyone got any other ideas?

  • Yeah Brian, that would work too. Just need to do it throught the Framework. It's for a component I'm working on.

  • using System.DirectoryServices;



    public void GetMaps(int site_index)

    {

    DirectoryEntry ent = new DirectoryEntry("IIS://localhost/w3svc");

    DirectoryEntry child = new DirectoryEntry();

    child = ent.Children.Find(site_index.ToString(),"IIsWebServer");

    Array arr = (Array)child.Properties["ScriptMaps"].Value;

    foreach(string map in arr)

    {

    // do whatever here

    }

  • forget my ending brace, but oh well. You know what I mean. ;)

  • Hello!



    Try look on IIS6 Resource Kit (should be freely downloaded from MS). There is a chapter on WMI access to IIS.

  • Is that how you detect if IIS is installed on a system?

Comments have been disabled for this content.