VBS运行时错误代码800A01B6

时间:2010-03-09 23:42:40

标签: vbscript runtime-error

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

它指的是:     MimeMapArray(i)= CreateObject(“MimeMap”)

你可以告诉我我做错了什么吗?这是完整的脚本。注意,我试图通过双击此VBS文件在XP OS上运行它。

' 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

1 个答案:

答案 0 :(得分:2)

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

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

    cscript scriptname.vbs

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

    其次,您似乎缺少createobject行前面的“set”。看看here以供参考。

    该行应如下所示:

    set MimeMapArray(i) = CreateObject("MimeMap")