tags:

views:

238

answers:

3

I am a newbie to VBS scripting. Thanks for all your comments! I fixed error 800A0401 now, thanks to 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
+5  A: 

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") 
Jay Riggs
I'm pretty sure u can. See website: http://msdn.microsoft.com/en-us/library/ms752346.aspx.When I tried putting Dim on separate line I got Expected Identifier error on Line 6, character 5. Which answers my question about line counting; Commented lines are counted.
salvationishere
@salvationishere: note that in that example, the variable `MimeTypesToAddArray` is being defined on line 6, then assigned a value on line 10... (and yes, both comment lines and blank lines count)
Shog9
When I updated your code with my change I not longer got the error you reported. I did get another one though which I was able to fix by removing the parenthesis from this line: MimeMapObj.PutEx(ADS_PROPERTY_UPDATE, "MimeMap", MimeMapArray)
Jay Riggs
@salv, I'mm pretty sure the code on that page _doesn't_ combine Dim with assignment. Perhaps you should look again.
paxdiablo
Sharp eyes, Jay! THis was the problem. I corrected this line but now I have a different error. Please see revised question.
salvationishere
Again, great job, Jay! I did do these as separate lines; see revised question above for new error. And Shog9 also kudos!
salvationishere
@salvationishere - remove the Set from line 13.
Jay Riggs
+1  A: 

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")
the empirical programmer
Yeah, this is the problem. Hard to remember for those of us used to C... Even worse once you throw VB.NET (which *does* allow it) into the mix.
Shog9
p.s. if you are doing more VBS look at downloading a different editor, such as Notepad++ (http://notepad-plus.sourceforge.net/uk/site.htm). It will give you syntax highlighting and show line and column numbers.
the empirical programmer
Great comment, Empirical Programmer! This fixed that error. I'm just googling this next error unless u happen to know answer off top of your head. Now I get 800A01B6 on Line 54, Character 5. This is line: MimeMapArray(i) = CreateObject("MimeMap")
salvationishere
+1  A: 

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()
Mark Biek
Thanks for the tip, Mark! Do u know though about the new error? (see updated question)
salvationishere
I believe the issue is that you don't need "set" when assigning the Array to MimeTypesToAddArray. Just MimeTypesToAddArray = Array()
Mark Biek