开发者

VBS Expected End of Statement

开发者 https://www.devze.com 2022-12-22 22:00 出处:网络
I am a newbie to VBS scripting.Thanks for all your comments!I fixed error 800A0401 now, thanks t开发者_Go百科o your helps.But now I\'m getting error 800A0414 on line 13, character 1 \"Object required\

I am a newbie to VBS scripting. Thanks for all your comments! I fixed error 800A0401 now, thanks t开发者_Go百科o your helps. 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", _

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

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


If you're going to combine a Dim statement with an assignment on the same line, you have to do it like this:

Dim MimeTypesToAddArray : MimeTypesToAddArray = Array()


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. VB6 did not allow this so I assume VBS does not either. 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")
0

精彩评论

暂无评论...
验证码 换一张
取 消