MimeMap: using WMI/ADSI in C#

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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)
 
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);
}
}
}
}
 
Back
Top