2010-03-09 300 views
0

我是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 

回答

2

我可以建議的第一件事就是使用cscript來執行。您可以獲得更多信息,不會像消息框一樣消失。

  1. 打開命令提示符(轉到開始, 運行,鍵入CMD)。
  2. 走到哪裏你的腳本 是並鍵入以下位置:

CSCRIPT scriptname.vbs

...其中scriptname.vbs是你的腳本的名稱。

其次,您似乎缺少createobject行前面的「set」。看看here作爲參考。

這行應該是這樣的:

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