Home All Groups Group Topic Archive Search About

MimeMap: using WMI/ADSI in C#

Author
14 Feb 2006 9:06 PM
Abhi
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 just gives me the name "MimeMap" but I
need to get a handle 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)

Author
15 Feb 2006 3:52 PM
Abhi
Here's 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);
            }
        }
    }
}



Show quote
"Abhi" wrote:

> 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 just gives me the name "MimeMap" but I
> need to get a handle 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)

AddThis Social Bookmark Button