VBS运行时错误代码800A01B6

VBS运行时错误代码800A01B6

问题描述:

我是VBS脚本的新手。我在54行以上的脚本中遇到了以上错误,下面脚本中的字符5。这个错误说“对象不支持这个属性或方法:'MimeMapArray'”。VBS运行时错误代码800A01B6

和线路,它指的是: MimeMapArray(I)=的CreateObject( “MimeMap”)

u能告诉我什么,我做错了什么?这是整个脚本。请注意,我试图通过双击此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 

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

  1. 打开命令提示符(转到开始, 运行,键入CMD)。
  2. 走到哪里你的脚本 是并键入以下位置:

CSCRIPT scriptname.vbs

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

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

这行应该是这样的:

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