加載時出現錯誤。
Set Arg = WScript.Arguments
set WshShell = createObject("Wscript.Shell")
Set Inp = WScript.Stdin
Set Outp = Wscript.Stdout
Sub VBSCmd
RawScript = Arg(1)
'Remove^from quoting command line and replace : with vbcrlf so get line number if error
Script = Replace(RawScript, "^", "")
Script = Replace(Script, "'", chr(34))
Script = Replace(Script, ":", vbcrlf)
'Building the script with predefined statements and the user's code
Script = "Dim gU" & vbcrlf & "Dim gdU" & vbcrlf & "Set gdU = CreateObject(" & chr(34) & "Scripting.Dictionary" & chr(34) & ")" & vbcrlf & "Function UF(L, LC)" & vbcrlf & "Set greU = New RegExp" & vbcrlf & "On Error Resume Next" & vbcrlf & Script & vbcrlf & "End Function" & vbcrlf
'Testing the script for syntax errors
On Error Resume Next
set ScriptControl1 = wscript.createObject("MSScriptControl.ScriptControl",SC)
With ScriptControl1
.Language = "VBScript"
.UseSafeSubset = False
.AllowUI = True
.AddCode Script
End With
With ScriptControl1.Error
If .number <> 0 then
Outp.WriteBlankLines(1)
Outp.WriteLine "User function syntax error"
Outp.WriteLine "=========================="
Outp.WriteBlankLines(1)
Outp.Write NumberScript(Script)
Outp.WriteBlankLines(2)
Outp.WriteLine "Error " & .number & " " & .description
Outp.WriteLine "Line " & .line & " " & "Col " & .column
Exit Sub
End If
End With
ExecuteGlobal(Script)
'Remove the first line as the parameters are the first line
'Line=Inp.readline
Do Until Inp.AtEndOfStream
Line=Inp.readline
LineCount = Inp.Line
temp = UF(Line, LineCount)
If err.number <> 0 then
outp.writeline ""
outp.writeline ""
outp.writeline "User function runtime error"
outp.writeline "==========================="
Outp.WriteBlankLines(1)
Outp.Write NumberScript(Script)
Outp.WriteBlankLines(2)
Outp.WriteLine "Error " & err.number & " " & err.description
Outp.WriteLine "Source " & err.source
Outp.WriteLine "Line number and column not available for runtime errors"
wscript.quit
End If
outp.writeline temp
Loop
End Sub
了Vbs
filter vbs "text of a vbs script"
使用冒號將單獨的語句和線條。如果您需要單引號,請使用單引號代替雙引號(39)。用^字符轉義括號和&符號。如果你需要使用字母(136)。
該函數被稱爲UF(用於UserFunction)。它有兩個參數,包含當前行的L和包含行數的LC。將腳本的結果設置爲UF。看例子。
有三個全局對象可用。未聲明的全局變量gU維護狀態。如果您需要多個變量,請將其用作數組。用於保存和訪問先前行的Dictionary對象gdU。並準備使用RegExp對象。
示例 此vbs腳本插入行號並將行設置爲Filter打印的函數UF。
filter vbs "uf=LC ^& ' ' ^& L"<"%systemroot%\win.ini"
這是它的外觀在內存
Dim gU
Set gdU = CreateObject("Scripting.Dictionary")
Set greU = New RegExp
Function UF(L, LC)
---from command line---
uf=LC & " " & L
---end from command line---
End Function
如果有語法錯誤過濾器會顯示調試信息。
通過[下面的鏈接](http://stackoverflow.com/a/25983099/2165759),您可以找到C#代碼來檢查VBScript代碼是否有語法錯誤,它使用Microsoft Script Control。 – omegastripes 2014-10-23 18:40:09