VBScript-800A0401–应为语句结尾



我正试图使用vbscript调用uninstall.exe,但我得到了一个

800A0401-预期状态结束

错误。

strPath ="""%ProgramFiles%qstopmotion 2.5.2uninstall.exe""" Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Run strPath Set WshShell = Nothing Wscript.Sleep 5000 set svc=getobject("winmgmts:rootcimv2") sQuery="select * from win32_process where name='Au_.exe'" set cproc=svc.execquery(sQuery) iniproc=cproc.count Do While iniproc = 1 wscript.sleep 5000 set svc=getobject("winmgmts:rootcimv2") sQuery="select * from win32_process where name='Au_.exe'" set cproc=svc.execquery(sQuery) iniproc=cproc.count Loop set cproc=nothing set svc=nothing

错误出现在字符63处,该字符位于三段引号的末尾。似乎无法正确逃离路径。有什么想法吗?

VBScript语法要求每一行都表示一个语句,在问题中的示例中,第一个语句是strPath变量的末尾,因为编写了更多的代码,VBScript返回编译错误

预期的语句结束

您可以通过整理代码来修复此问题,使每条语句都是自己的一行;

strPath ="""%ProgramFiles%qstopmotion 2.5.2uninstall.exe"""
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run strPath
Set WshShell = Nothing
Wscript.Sleep 5000
set svc=getobject("winmgmts:rootcimv2")
sQuery="select * from win32_process where name='Au_.exe'"
set cproc=svc.execquery(sQuery)
iniproc=cproc.count
Do While iniproc = 1
wscript.sleep 5000
set svc=getobject("winmgmts:rootcimv2")
sQuery="select * from win32_process where name='Au_.exe'"
set cproc=svc.execquery(sQuery)
iniproc=cproc.count
Loop
set cproc=nothing
set svc=nothing

如果您确实希望这一切在一行上运行,VBScript为此提供了语句分隔符(:(,因此以下内容也可以接受,但可读性不强(不建议这样做(;

strPath ="""%ProgramFiles%qstopmotion 2.5.2uninstall.exe""" : Set WshShell = WScript.CreateObject("WScript.Shell") : WshShell.Run strPath : Set WshShell = Nothing : Wscript.Sleep 5000 : set svc=getobject("winmgmts:rootcimv2") : sQuery="select * from win32_process where name='Au_.exe'" : set cproc=svc.execquery(sQuery) : iniproc=cproc.count : Do While iniproc = 1 : wscript.sleep 5000 : set svc=getobject("winmgmts:rootcimv2") : sQuery="select * from win32_process where name='Au_.exe'" : set cproc=svc.execquery(sQuery) : iniproc=cproc.count : Loop : set cproc=nothing : set svc=nothing

有用的链接

  • VBScript,冒号的用途

最新更新