1

I am trying to use vbscript to call uninstall.exe, but I get a

800A0401 - Expected End of state

error.

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

The error is at character 63, which is at the end of the tripe quotes. Can't seem to escape the path correctly. Any ideas?

user692942
  • 16,398
  • 7
  • 76
  • 175
  • 1
    Because the end of the string IS the expected end of that particular statement. Each statement should end with a carriage return or if you want the statements to span the same lines separate them with `:` at the end of each statement. – user692942 Jun 02 '21 at 07:46
  • 1
    @K-Dawg What are you talking about there is no such statement as `End Set` in VBScript?? – user692942 Jun 02 '21 at 07:52
  • 1
    Did you mean to post the code as all one line, or is it actually over many lines? Please [edit] your code to fix it if so. – Ken Y-N Jun 02 '21 at 07:52
  • @user692942 It's been a while since I've touched VBScript. I was looking at this document here: https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/set-statement. Looking at it again I can see that this is for property accessors on a class. – K-Dawg Jun 02 '21 at 09:30
  • 1
    @K-Dawg Maybe it wasn't VBScript at all? That documentation is for VB.Net, while based on the Visual Basic programming language is a completely different technology grounded in the .Net CLR. For reference, this is the [Official VBScript Documentation](https://learn.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/scripting-articles/t0aew7h6(v=vs.84)). – user692942 Jun 02 '21 at 10:01
  • 1
    @user692942 ah thank you for that. It's been a while since I used VB in any form. I'll delete my initial comment ("I think you're possibly missing End Set after using Set") just so that it doesn't give anyone an incorrect steer in the future. – K-Dawg Jun 03 '21 at 07:47

1 Answers1

1

VBScript syntax expects each line to represent a statement, in the example in the question the first statement is the end of your strPath variable, because further code is written VBScript returns a compilation error

Expected end of statement

You can fix this by tidying the code so each statement is it's own line;

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

If you did want this all to run on one line VBScript provides the Statement Separator character (:) for this purpose so the following would also be acceptable, but not very readable (would not recommend doing this);

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

Useful Links

user692942
  • 16,398
  • 7
  • 76
  • 175