0

我是 VBS 脚本的新手。我在下面脚本中的第 54 行字符 5 上遇到错误。此错误显示“对象不支持此属性或方法:'MimeMapArray'”。

它所指的行是: MimeMapArray(i) = CreateObject("MimeMap")

你能告诉我我做错了什么吗?这是整个脚本。注意,我试图通过双击这个 VBS 文件在 XP 操作系统上运行它。

' This script adds the necessary Windows Presentation Foundation MIME types 
' to an IIS Server.
' To use this script, just double-click or execute it from a command line.
' Running this script multiple times results in multiple entries in the IIS MimeMap.
' Set the MIME types to be added
Dim MimeMapObj
Dim MimeMapArray
Dim WshShell
Dim oExec
Const ADS_PROPERTY_UPDATE = 2

Dim MimeTypesToAddArray
MimeTypesToAddArray = Array(".manifest", "application/manifest", ".xaml", _
    "application/xaml+xml", ".application", "application/x-ms-application", _
    ".deploy", "application/octet-stream", ".xbap", "application/x-ms-xbap", _
    ".xps", "application/vnd.ms-xpsdocument")

' Get the mimemap object 
Set MimeMapObj = GetObject("IIS://LocalHost/MimeMap")

' Call AddMimeType for every pair of extension/MIME type
For counter = 0 to UBound(MimeTypesToAddArray) Step 2
    AddMimeType MimeTypesToAddArray(counter), MimeTypesToAddArray(counter+1)
Next

' Create a Shell object
Set WshShell = CreateObject("WScript.Shell")

' Stop and Start the IIS Service
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

' Report status to user
WScript.Echo "Windows Presentation Foundation MIME types have been registered."

' AddMimeType Sub
Sub AddMimeType(ByVal Ext, ByVal MType)

    ' Get the mappings from the MimeMap property. 
    MimeMapArray = MimeMapObj.GetEx("MimeMap")

    ' Add a new mapping. 
    i = UBound(MimeMapArray) + 1
    ReDim Preserve MimeMapArray(i)
    MimeMapArray(i) = CreateObject("MimeMap")
    MimeMapArray(i).Extension = Ext
    MimeMapArray(i).MimeType = MType
    MimeMapObj.PutEx ADS_PROPERTY_UPDATE, "MimeMap", MimeMapArray
    MimeMapObj.SetInfo()

End Sub
4

1 回答 1

2

我可以建议的第一件事是使用 cscript 执行。您可以获得更多不会像消息框一样消失的信息。

  1. 打开命令提示符(开始,运行,键入 CMD)。
  2. 转到脚本所在的位置并键入以下内容:

cscript 脚本名.vbs

...其中 scriptname.vbs 是您的脚本的名称。

其次,您似乎缺少 createobject 行前面的“集合”。看看这里以供参考。

该行应如下所示:

set MimeMapArray(i) = CreateObject("MimeMap")
于 2010-03-15T03:01:27.313 回答