简体   繁体   English

VBS预期结束声明

[英]VBS Expected End of Statement

I am a newbie to VBS scripting. 我是VBS脚本的新手。 Thanks for all your comments! 谢谢你们的评论! I fixed error 800A0401 now, thanks to your helps. 由于您的帮助,我现在修复了错误800A0401。 But now I'm getting error 800A0414 on line 13, character 1 "Object required", which refers to line: Set MimeTypesToAddArray = Array(".manifest", "application/manifest", ".xaml", _ 但是现在我在第13行出现错误800A0414,字符1“需要对象”,它指向以下行:Set MimeTypesToAddArray = Array(“。manifest”,“ application / manifest”,“ .xaml”,_

Now I understand how line counting works; 现在,我了解了行计数的工作原理; it does count comment lines. 它确实计算注释行。 I am still reviewing all of your suggestions, but if u have any tips on how I can fix this error now that would be super! 我仍在审核您的所有建议,但如果您现在就如何解决此错误有任何提示,那将是超级好!

(I do not agree about needing to put "Dim" on separate line from type values because I've seen so many examples of doing this. Are any of u VBS experts?0 (我不同意需要将“ Dim”放在类型值的不同行上,因为我已经看到了很多这样做的例子。u VBS专家中有谁吗?0

' 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
Set 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

I don't think you can Dim a variable and write to it on the same line. 我认为您不能将变量变暗并在同一行上写入它。

Try these as separate lines: 尝试将其作为单独的行:

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") 

I'm not familiar with VBS just VB6 but I believe the error is that you are doing a DIM and an a assignment on the same line. 我对VBS和VB6并不熟悉,但是我认为错误是您在同一行上执行DIM和分配。 VB6 did not allow this so I assume VBS does not either. VB6不允许这样做,因此我认为VBS也不允许。 So maybe something like this is what you want. 所以也许您想要这样的东西。 Also it does look like it counts blank lines and comments. 而且它看起来确实算空白行和注释。

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")

如果要将Dim语句与同一行的赋值合并,则必须这样做:

Dim MimeTypesToAddArray : MimeTypesToAddArray = Array()

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

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