Forum Discussion
HKosova
Alumni
14 years agoHi Joseph,
First of all, to check whether an application exists in TestedApps, you need to use TestedApps.Find:
First of all, to check whether an application exists in TestedApps, you need to use TestedApps.Find:
if it doesn't exist.
Next, there's no need to escape backslashes in VBScript, because they aren't special characters. So, path strings should be simply like this: C:\Program Files (x86)\Mozilla Firefox\.
You're also missing End If's after each If block.
Finally, I'd recommend using the %ProgramFiles% environment variable in place of the hard-coded path to the Program Files folder. The benefit is that it will automatically resolve to C:\Program Files or C:\Program Files (x86) depending on the OS bitness. This way, the script will be simpler and neater. :)Sub CheckOS
If TestedApps.Find("firefox") >= 0 Then
TestedApps.firefox.Path = "%ProgramFiles%\Mozilla Firefox"
End If
If TestedApps.Find("iexplore") >= 0 Then
TestedApps.iexplore.Path = "%ProgramFiles%\Internet Explorer"
End If
If TestedApps.Find("AcroRd32") >= 0 Then
TestedApps.AcroRd32.Path = "%ProgramFiles%\Adobe\Reader 9.0\Reader"
End If
End Sub
Or, using a With block and one-line If's:Sub CheckOS
With TestedApps
If .Find("firefox") >= 0 Then .firefox.Path = "%ProgramFiles%\Mozilla Firefox"
If .Find("iexplore") >= 0 Then .iexplore.Path = "%ProgramFiles%\Internet Explorer"
If .Find("AcroRd32") >= 0 Then .AcroRd32.Path = "%ProgramFiles%\Adobe\Reader 9.0\Reader"
End With
End Sub