We help IT Professionals succeed at work.

Why am I getting this error with this VB Script?

Freeday
Freeday asked
on
Medium Priority
878 Views
Last Modified: 2012-05-06
The error is

Windows Script Host
---------------------------
Script: CDocuments and Settings\cs-ads-mbb30\Desktop\arms.vbs
Line: 5
Char: 121
Error: Expected 'Then'
Code: 800A03F9
Source: Microsoft VBScript compilation error

Set shell= WScript.CreateObject("WScript.Shell")
username = shell.ExpandEnvironmentStrings("%USERNAME%")
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("C:\Documents and Settings\" & username & "\Start Menu\Programs\End2End, Inc\ARMS V2 R3.appref-ms")
Then
Wscript.Echo "ARMS Enterprise V2 R3 is already installed for " & username & " on this
computer. Click OK to close."
Else
Wscript.Echo "ARMS Enterprise V2 R3 is not installed for " & username & " on this
computer. Please click install when prompted."
CreateObject("Wscript.Shell").Run "\\cs-metroplex.cwru.edu\ARMSInstaller\Setup.exe"
 
End If

Open in new window

Comment
Watch Question

try to move then to the same line as if


Set shell= WScript.CreateObject("WScript.Shell")
username = shell.ExpandEnvironmentStrings("%USERNAME%")
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("C:\Documents and Settings\" & username & "\Start Menu\Programs\End2End, Inc\ARMS V2 R3.appref-ms") Then
Wscript.Echo "ARMS Enterprise V2 R3 is already installed for " & username & " on this
computer. Click OK to close."
Else
Wscript.Echo "ARMS Enterprise V2 R3 is not installed for " & username & " on this
computer. Please click install when prompted."
CreateObject("Wscript.Shell").Run "\\cs-metroplex.cwru.edu\ARMSInstaller\Setup.exe"
 
End If

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Commented:
In order for the IF statement to work you need to have IF Then in one line.

You cannot have your IF Else statement like below:

IF
Then
End IF

Solution
If    then
Else
End IF


Hope this solves your problem
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.