VBScript不断变换错误,例如第10行和其他人预期的声明

时间:2018-01-21 21:40:08

标签: vbscript scripting wsh

我似乎在第10行遇到了一些问题。可能还有其他错误。我已经运行调试来尝试隔离问题,非常感谢任何帮助。

Option Explicit On
Dim fso

Set FSO = CreateObject("Scripting.FileSystemObject")

FSO.CopyFile "C:\Users\usr\Desktop\UMAD.vbs", "C:\Users\Public\Music\"
FSO.CopyFile "C:\Users\usr\Desktop\DVD.vbs", "C:\Users\Public\Documents\"
FSO.CopyFile "C:\Users\usr\Desktop\back.vbs", "C:\Users\Public\Videos\" 

Set WshShell = WScript.CreateObject("WScript.Shell")
Sub shell()
    Dim objShell
    Set objShell = WScript.CreateObject( "WScript.Shell" )

    'run with wscript
    WshShell.Run("""C:\Users\Public\Music\UMAD.vbs"" ""C:\Users\Public\Music\UMAD.vbs""")

    WScript.Sleep 20000

    'run with cscript
    objShell.Run("""C:\Users\Public\Documents\DVD.vbs\"" ""C:\Users\Public\Documents\DVD.vbs\""")

    WScript.Sleep 5000

    'run with the default program for vbs files (usually cscript)
    objShell.Run("""C:\Users\Public\Videos\back.vbs""")
End Sub

1 个答案:

答案 0 :(得分:0)

一个问题,一个答案。这个答案属于第一个问题“第10行预期的声明。”

如果我算的正确,第10行是Set WshShell = WScript.CreateObject("WScript.Shell")

您面临的问题是,使用Option Explicit时必须声明所有变量。所以你需要声明你的WshShell

Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")