2010-03-10 106 views
1

我想从Windows资源管理器(IIS管理器6)运行.VBS脚本,并且是一个新手VBScript编程。运行以下代码时出现以上错误。我究竟做错了什么?我只需要生成IIS MIME类型!VBS运行时错误800A000D - 类型不匹配

错误详细信息:第49行,char 5;
其中线49:现在

MimeMapArray = MimeMapObj.GetEx("MimeMap") 

代码固定。这是它应该看起来如何:

' 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." 

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

    ' Get the mappings from the MimeMap property. 
    ' Add a new mapping. 
    For i = 0 to 14 
' UBound(MimeMapArray) - 1 
    ReDim Preserve MimeMapArray(i) 
    Set MimeMapArray(i) = CreateObject("MimeMap") 
    MimeMapArray(i).Extension = Ext 
    MimeMapArray(i).MimeType = MType 
    MimeMapObj.PutEx ADS_PROPERTY_UPDATE, "MimeMap", MimeMapArray 
    MimeMapObj.SetInfo() 
Next 

End Sub 

回答

0

没关系,我想出了这个问题。正确的版本现在显示。