简体   繁体   English

VBS运行时错误代码800A01B6

[英]VBS Runtime error code 800A01B6

I am a newbie to VBS scripting. 我是VBS脚本的新手。 I am getting above error on line 54, character 5 in script below. 我在以下脚本中的第54行第5个字符上遇到了错误。 This error says "Object doesn't support this property or method: 'MimeMapArray'". 该错误显示“对象不支持此属性或方法:'MimeMapArray'”。

And line it is referring to is: MimeMapArray(i) = CreateObject("MimeMap") 它所指的行是:MimeMapArray(i)= CreateObject(“ MimeMap”)

Can u tell me what I am doing wrong? 你能告诉我我做错了吗? Here is the script in its entirety. 这是完整的脚本。 Note, I am trying to run this on an XP OS by double-clicking this VBS file. 注意,我试图通过双击此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

The first thing I can suggest is use cscript to execute. 我可以建议的第一件事是使用cscript执行。 You can get more information that won't go away like with a message box. 您可以通过消息框获得更多不会消失的信息。

  1. Open a command prompt (go to start, run, type CMD). 打开命令提示符(开始,运行,键入CMD)。
  2. Go to the location where your script is and type the following: 转到脚本所在的位置,然后键入以下内容:

cscript scriptname.vbs cscript scriptname.vbs

...where scriptname.vbs is the name of your script. ...其中scriptname.vbs是脚本的名称。

Second, you appear to be missing the "set" in front of your createobject line. 其次,您似乎缺少createobject行前面的“集合”。 Have a look here for reference. 在这里看看以供参考。

That line should look like: 该行应如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM