添加http mime类型脚本

Option Explicit
Dim MimeTypesDic,MimeMapObj,mimekey
Set MimeTypesDic=CreateObject("scripting.dictionary")
 
'设置要添加的MIME类型,参照格式自己随便添
MimeTypesDic.add ".flv","flv-application/octet-stream"
MimeTypesDic.add ".rar","application/x-zip-compressed"
 
'下面这个对象是根结点
Set MimeMapObj = GetObject("IIS://LocalHost/MimeMap")
'这个表示对单一站点设置
'Set MimeMapObj = GetObject("IIS://LocalHost/W3SVC/1/root")
For each mimekey in MimeTypesDic.keys
     AddMimeType mimekey,MimeTypesDic(mimekey)
Next
set MimeMapObj=nothing
wscript.echo "设置成功,需要重启IIS。"
 
'函数
Sub AddMimeType (Ext, MType)
    dim intMimeMap,MimeMapArray,isfound,MimeExt
    MimeMapArray = MimeMapObj.GetEx("MimeMap")
    isfound=false
 
    for intMimeMap=0 to ubound(MimeMapArray)
        mimeExt=MimeMapArray(intMimeMap).Extension
        '检查是否有重复,如果找到就表示只更新这条
      if MimeExt=Ext then isfound=true:exit for
    next
 
    if not isfound then	'表示要添加
      Redim Preserve MimeMapArray(intMimeMap)
        Set MimeMapArray(intMimeMap) = CreateObject("MimeMap")
        MimeMapArray(intMimeMap).Extension = Ext	'扩展名
    end if
    MimeMapArray(intMimeMap).MimeType = MType	'类型
 
   MimeMapObj.PutEx 2, "MimeMap", MimeMapArray
    MimeMapObj.SetInfo
    set MimeMapArray(intMimeMap)=nothing
End Sub

你可能感兴趣的:(脚本,ext,扩展,each,IIS)