Dim MimeMapObj, MimeMapArray, MimeTypesToAddArray, WshShell, oExec, siteNumber, i    
Const ADS_PROPERTY_UPDATE = 2    
' Set the MIME types to be added    
MimeTypesToAddArray = Array(".doc", "application/msword", _
    ".docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", _
    ".xls", "application/vnd.ms-excel", _
    ".xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", _
    ".odf", "application/vnd.oasis.opendocument.formula", _
    ".zip", "application/x-zip-compressed", _
    ".rar", "application/octet-stream", _
    ".7z", "application/x-7z-compressed", _
    ".iso", "application/octet-stream", _
    ".exe", "application/octet-stream", _
    ".pdf", "application/pdf", _
    ".ppt", "application/vnd.ms-powerpoint", _
    ".pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", _
    ".dwg", "application/octet-stream", _
    ".psd", "application/octet-stream", _
    ".wmv", "video/x-ms-wmv", _
    ".mp3", "audio/mpeg", _
    ".rmvb", "application/vnd.rn-realmedia", _
    ".wps", "application/vnd.ms-works", _
    ".cdr", "application/octet-stream")    
   
' Get the mimemap object
' 第一个参数表示IIS下的站点号
if Wscript.Arguments.count = 0 then
    siteNumber = "1"
else
    siteNumber = Wscript.Arguments(0)
end if
Set MimeMapObj = GetObject("IIS://LocalHost/W3SVC/" & siteNumber & "/root")    
   
' Call AddMimeType for every pair of extension/MIME type    
For counter = 0 to UBound(MimeTypesToAddArray) Step 2   
     AddMimeType MimeTypesToAddArray(counter), MimeTypesToAddArray(counter+1)    
Next    

'Restart the IIS Service     
Set WshShell = CreateObject("WScript.Shell")  
WshShell.Run "net stop w3svc",0,true 
WshShell.Run "net start w3svc",0,true  
'Set oExec = WshShell.Exec("net stop w3svc")    
'Do While oExec.Status = 0   
'     WScript.Sleep 100   
'Loop    
'Set oExec = WshShell.Exec("net start w3svc")    
'Do While oExec.Status = 0   
'     WScript.Sleep 100   
'Loop    
'Set oExec = Nothing    

'如果是直接双击无参运行，则提示成功
if Wscript.Arguments.count = 0 then WScript.Echo "添加MIME类型成功！"   
   
' AddMimeType Sub    
Sub AddMimeType (Ext, MType)    
    MimeMapArray = MimeMapObj.GetEx("MimeMap")  

     '有重复，则退出  
    for i=0 to ubound(MimeMapArray)     
      if MimeMapArray(i).Extension=Ext then exit sub
    next
 
     ' Add a new mapping.    
     i = UBound(MimeMapArray) + 1    
     Redim Preserve MimeMapArray(i)    
     Set MimeMapArray(i) = CreateObject("MimeMap")    
     MimeMapArray(i).Extension = Ext    
     MimeMapArray(i).MimeType = MType    
     MimeMapObj.PutEx ADS_PROPERTY_UPDATE, "MimeMap", MimeMapArray    
     MimeMapObj.SetInfo    
End Sub   