首页 > 解决方案 > VBScript - 800A0401 - 预期的语句结束

问题描述

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

800A0401 - 预期状态结束

错误。

strPath ="""%ProgramFiles%\qstopmotion 2.5.2\uninstall.exe""" Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Run strPath Set WshShell = Nothing Wscript.Sleep 5000 set svc=getobject("winmgmts:root\cimv2") 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:root\cimv2") 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

解决方案


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

预期的语句结束

你可以通过整理代码来解决这个问题,这样每个语句都是它自己的行;

strPath ="""%ProgramFiles%\qstopmotion 2.5.2\uninstall.exe"""
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run strPath
Set WshShell = Nothing
Wscript.Sleep 5000
set svc=getobject("winmgmts:root\cimv2")
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:root\cimv2")
  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.2\uninstall.exe""" : Set WshShell = WScript.CreateObject("WScript.Shell") : WshShell.Run strPath : Set WshShell = Nothing : Wscript.Sleep 5000 : set svc=getobject("winmgmts:root\cimv2") : 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:root\cimv2") : sQuery="select * from win32_process where name='Au_.exe'" : set cproc=svc.execquery(sQuery) : iniproc=cproc.count : Loop : set cproc=nothing : set svc=nothing

有用的链接


推荐阅读