2010-03-09 96 views
0

這是一個簡單的VBS腳本。但是當我雙擊這個時,我得到第一行的無效字符800A0408,字符1,我認爲它是第一個「Dim」。我是VBS新手 - 你能告訴我我做錯了什麼嗎?僅供參考,我安裝了XP操作系統和IIS6管理器。VBS無效字符

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

Dim MimeMapObj 
Dim MimeMapArray 
Dim WshShell 
Dim oExec 
Const ADS_PROPERTY_UPDATE = 2 

' Set the MIME types to be added 
Dim 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

如果使用vim打開文件並使用ex命令'set list',它會顯示任何可能導致此問題的不可見字符。

2

報價http://classicasp.aspfaq.com/general/why-do-i-get-800a0408-errors.html

如果你從其它的 來源(如網站,其他 編輯器等),粘貼代碼,你經常一起 角色帶來不中 露面記事本,但是,目前 - 或確實顯示爲不可打印的字符,看起來像很小的 正方形。如果您正在查看有問題的行 ,並且它不是簡單的 未關閉的字符串或過早的 回車,請嘗試刪除 行,然後手動重新輸入它們 。這應該消除 字符堵塞流的「隱形」問題的可能性。

+0

謝謝,是的,我之前讀過。但是,我在記事本中查看過這個文件並重新輸入了第一行,但我仍然有同樣的錯誤。任何其他想法?語法正確,否?是不是說第一個「昏暗」錯誤? – salvationishere 2010-03-09 20:51:03

0

保存文件時檢查編碼,必須是ANSI記事本