Jump to content

Elseif giving me grief


Recommended Posts

Hi,

I am a casual user of AutoIT, and can usually puzzle it out when I've made a mistake, but I have to admit I'm stumped as to why this is a code violation:

Func UninstallClient()
    If FileExists(@WindowsDir & "\myexec\myexecexec.exe") or (@SystemDir & "\myexec\myexecexec.exe") Then
        If FileExists(@WindowsDir & "\myexecsetup\myexecsetup.exe") Then ShellExecuteWait("myexecsetup.exe","/uninstall",@WindowsDir & "\myexecsetup","",@SW_HIDE)
        Elseif FileExists(@SystemDir & "\myexec\myexecsetup.exe") Then ShellExecuteWait("myexecsetup.exe","/uninstall",@SystemDir & "\myexec","",@SW_HIDE)
        EndIf
    EndIf
 
EndFunc ;==UninstallClient

The error I get indicates I have a syntax error after adding in the nested ElseIf's.  Prior to that it looked like this:

Func UninstallClient()
    If FileExists(@WindowsDir & "\myexec\myexecexec.exe") or (@SystemDir & "\myexec\myexecexec.exe") Then
        If FileExists(@WindowsDir & "\myexecsetup\myexecsetup.exe") Then ShellExecuteWait("myexecsetup.exe","/uninstall",@WindowsDir & "\myexecsetup","",@SW_HIDE)
        if FileExists(@SystemDir & "\myexec\myexecsetup.exe") Then ShellExecuteWait("myexecsetup.exe","/uninstall",@SystemDir & "\myexec","",@SW_HIDE)
    EndIf
    
EndFunc ;==UninstallClient

Which just doesn't look right to me, however the script checker seems to think it's fine.  

Just to clarify what I'm after, I'm looking for a certain file which can be in one of two places, if it exists in either one, then launch an uninstaller which can also be on one of two (other) places.  I know this is not clean and could have been written better, so helpful suggestions as to how to better accomplish this are welcome, however, foremost I'm looking to find out why the Elseif causes a syntax error.

Thoughts?

Thanks!

John

Edited by BiggJohn
Link to comment
Share on other sites

 

In this case you need to put the code after Then on a new line

Func UninstallClient()

    If FileExists(@WindowsDir & "\myexec\myexecexec.exe") Or (@SystemDir & "\CCM\ccmexec.exe") Then
        If FileExists(@WindowsDir & "\myexecsetup\myexecsetup.exe") Then
            ShellExecuteWait("myexecsetup.exe", "/uninstall", @WindowsDir & "\myexecsetup", "", @SW_HIDE)
        ElseIf FileExists(@SystemDir & "\myexec\myexecsetup.exe") Then
            ShellExecuteWait("myexecsetup.exe", "/uninstall", @SystemDir & "\myexec", "", @SW_HIDE)
        EndIf
    EndIf

EndFunc   ;==>UninstallClient

 

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...