Coffeehouse Thread

2 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Retrieving MimeMap attr value from LM/MimeMap key

Back to Forum: Coffeehouse
  • User profile image
    kulkarna

    Hi-

    I have a need to programmatically (C#) retrieve the value of the
    attribute "MimeMap" (ID = 6015) from the LM/MimeMap from my machine's metabase.

    Using the Select * from IIsMimeMap jsut gives me the name "MimeMap" but I need to get a hnadle to the attribute beneath it to retrieve the
    "MimeMap"...a multistring value.

    Any ideas?
    Thanks!
    -abhi

    kulkarnaATgmail.com

    PS:- I'd like to use either ADSI or WMI (preferable)

  • User profile image
    kulkarna

        I found the solution:

      

    using System;

    using System.Management;

    using System.Windows.Forms;

     

    namespace WMISample

    {

        public class MyWMIQuery

        {

            public static void Main()

            {

                try

                {

                    ManagementObjectSearcher searcher =

                        new ManagementObjectSearcher("root\\MicrosoftIISv2",

                        "SELECT * FROM IIsMimeMapSetting");

     

                    foreach (ManagementObject queryObj in searcher.Get())

                    {

                        Console.WriteLine("-----------------------------------");

                        Console.WriteLine("IIsMimeMapSetting instance");

                        Console.WriteLine("-----------------------------------");

     

                        if(queryObj["AdminACLBin"] == null)

                            Console.WriteLine("AdminACLBin: {0}", queryObj["AdminACLBin"]);

                        else

                        {

                            Byte[] arrAdminACLBin = (Byte[])(queryObj["AdminACLBin"]);

                            foreach (Byte arrValue in arrAdminACLBin)

                            {

                                Console.WriteLine("AdminACLBin: {0}", arrValue);

                            }

                        }

                        Console.WriteLine("Caption: {0}", queryObj["Caption"]);

                        Console.WriteLine("Description: {0}", queryObj["Description"]);

     

                        if(queryObj["MimeMap"] == null)

                            Console.WriteLine("MimeMap: {0}", queryObj["MimeMap"]);

                        else

                        {

                            Object[] arrMimeMap = (Object[])(queryObj["MimeMap"]);

                            foreach (Object arrValue in arrMimeMap)

                            {

                                Console.WriteLine("MimeMap: {0}", arrValue);

                            }

                        }

                        Console.WriteLine("Name: {0}", queryObj["Name"]);

                        Console.WriteLine("SettingID: {0}", queryObj["SettingID"]);

                    }

                }

                catch (ManagementException e)

                {

                    MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);

                }

            }

        }

    }


Conversation locked

This conversation has been locked by the site admins. No new comments can be made.