Listing the Default IIS MIME Map Settings Using WSH

Izjava o odricanju odgovornosti za sadržaj o otpisanom proizvodu u bazi znanja

Ovaj je članak napisan o proizvodu za koji Microsoft više ne pruža podršku. Članak će stoga ostati nepromijenjen i više se neće ažurirati.


This article describes how to create a Windows Scripting Host (WSH) script to list the default Multipurpose Internet Mail Extensions (MIME) Map settings for a server running Microsoft Internet Information Services (IIS).

More Information

Multipurpose Internet Mail Extensions (MIME) is a way of configuring browsers or mail clients to view files that are in multiple formats based on a MIME Type. MIME Mapping is a process by which IIS maps files by their extensions to a particular MIME Type. For example, a file with a .htm extension has a MIME Type of "text/html," whereas a file with a .gif extension has a MIME Type of "image/gif."

When a request is made by a client for a particular file, IIS uses the MIME Map to determine the correct MIME Type that the client will be receiving. IIS contains a large list of default MIME Types to use, and returns a MIME type of "application/octet-stream" for any file extension that is not explicitly mapped.

When Web administrators create or store new file formats with extensions that may be undefined, the following WSH code may help determine the contents of the default MIME Types list by displaying a sorted list of all current MIME Type definitions.

Listing the Default MIME Map

Copy the following WSH code and save it as Mimemaps.vbs:
Option Explicit

Dim objMimeMap
Dim varMimeMap
Dim intMimeMap
Dim objDictionary
Dim intCount
Const dictKey = 1
Const dictItem = 2

Set objDictionary = CreateObject("Scripting.Dictionary")
Set objMimeMap = GetObject("IIS://localhost/mimemap")
varMimeMap = objMimeMap.Get("MimeMap")

If IsArray(varMimeMap) Then
For intCount = LBound(varMimeMap) To UBound(varMimeMap)
objDictionary.Add varMimeMap(intCount).Extension, varMimeMap(intCount).MimeType
SortDictionary objDictionary,dictKey
intMimeMap = objDictionary.Count
WScript.Echo "Total MIME Map Entries: " & intMimeMap & vbCrLf
WScript.Echo "Extension" & vbTab & "MIME Type"
For Each varMimeMap in objDictionary
WScript.Echo varMimeMap & vbTab & objDictionary(varMimeMap)
End If

Function SortDictionary(objDict,intSort)
Dim strDict()
Dim objKey
Dim strKey,strItem
Dim X,Y,Z
Z = objDict.Count
If Z > 1 Then
ReDim strDict(Z,2)
X = 0
For Each objKey In objDict
strDict(X,dictKey) = CStr(objKey)
strDict(X,dictItem) = CStr(objDict(objKey))
X = X + 1
For X = 0 to (Z - 2)
For Y = X to (Z - 1)
If StrComp(strDict(X,intSort),strDict(Y,intSort),vbTextCompare) > 0 Then
strKey = strDict(X,dictKey)
strItem = strDict(X,dictItem)
strDict(X,dictKey) = strDict(Y,dictKey)
strDict(X,dictItem) = strDict(Y,dictItem)
strDict(Y,dictKey) = strKey
strDict(Y,dictItem) = strItem
End If
For X = 0 to (Z - 1)
objDict.Add strDict(X,dictKey), strDict(X,dictItem)
End If
End Function

Run the WSH script from a command prompt using the following syntax:

The output should be similar to the following:
Microsoft (R) Windows Script Host Version 5.1 for Windows
Copyright (C) Microsoft Corporation 1996-1999. All rights reserved.

Total MIME Map Entries: 189

Extension MIME Type
.* application/octet-stream
.323 text/h323
.acx application/internet-property-stream
.ai application/postscript
.aif audio/x-aiff
.aifc audio/aiff
.aiff audio/aiff
.asf video/x-ms-asf
.asr video/x-ms-asf
.asx video/x-ms-asf
.au audio/basic
-- More --

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:


For more information on Microsoft's scripting technologies, see the Microsoft Developer Network web site at the following URL:

ID članka: 246068 - posljednja izmjena: 19. lip 2014. - verzija: 1

Povratne informacije