Check if file exist in any of two places and run it Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
apoklyps3
Posts: 113
Joined: 13 Feb 2016, 13:20

Check if file exist in any of two places and run it

Post by apoklyps3 » 22 May 2018, 02:38

I want to create a script that checks if teamviewer is install and then runs it if it is or downloads and runs it if it isn't.
The issue I have is that I want this script to be multilanguage compatible and both 32 bit and 64 bit compatible.
teamviewer installs in 32bit folder of windows, so on a 32bit system it will be located in program files and on a 64bit OS version it will be in program files (x86) folder.

so far I came up with this

Code: Select all

if FileExist("%programfiles%\TeamViewer\TeamViewer.exe | %programfiles(x86)%\TeamViewer\TeamViewer.exe")
what should follow so teamviewer.exe is ran no mather what location is it found in and if not to go to the next line wich will be download code ?
Last edited by apoklyps3 on 22 May 2018, 04:03, edited 1 time in total.
swagfag
Posts: 1200
Joined: 11 Jan 2017, 17:59

Re: Check if file exist in two places and run it

Post by swagfag » 22 May 2018, 03:33

Code: Select all

EnvGet, ProgramFiles32, ProgramFiles(x86)
teamviewer := "\TeamViewer\TeamViewer.exe"
if FileExist(ProgramFiles . teamviewer || ProgramFiles32 . teamviewer)
apoklyps3
Posts: 113
Joined: 13 Feb 2016, 13:20

Re: Check if file exist in two places and run it

Post by apoklyps3 » 22 May 2018, 03:40

thanks.
but it seems to be missing something, the run code for wichever location it found in. it only seems to check if teamviewer exists...
Would this work also on windows in another localization? they have different names for "program files" that's why I prefered %programfiles% style
swagfag
Posts: 1200
Joined: 11 Jan 2017, 17:59

Re: Check if file exist in two places and run it

Post by swagfag » 22 May 2018, 03:55

both locations are fetched from their respective environment variables, so i cant imagine a different language playing a role here.
Last edited by swagfag on 22 May 2018, 05:20, edited 1 time in total.
apoklyps3
Posts: 113
Joined: 13 Feb 2016, 13:20

Re: Check if file exist in two places and run it

Post by apoklyps3 » 22 May 2018, 04:02

how do I go about running the file if found any of the defined locations?
swagfag
Posts: 1200
Joined: 11 Jan 2017, 17:59

Re: Check if file exist in any of two places and run it

Post by swagfag » 22 May 2018, 05:26

Code: Select all

EnvGet, ProgramFiles32, ProgramFiles(x86)
teamviewer := "\TeamViewer\TeamViewer.exe"
teamviewer32 := ProgramFiles32 . teamviewer
teamviewer64 := ProgramFiles . teamviewer

if FileExist(teamviewer64)
	Run % teamviewer64
else if FileExist(teamviewer32)
	Run % teamviewer32
apoklyps3
Posts: 113
Joined: 13 Feb 2016, 13:20

Re: Check if file exist in any of two places and run it

Post by apoklyps3 » 22 May 2018, 05:28

amazing.thanks
apoklyps3
Posts: 113
Joined: 13 Feb 2016, 13:20

Re: Check if file exist in any of two places and run it  Topic is solved

Post by apoklyps3 » 22 May 2018, 07:06

unfortunately now I'm getting trouble with installation or not teamviwer if it's not detected in the specified folders.
added

Code: Select all

if !FileExist("teamviewer64" || "teamviewer32")
{
UrlDownloadToFile, https://download.teamviewer.com/download/TeamViewer_Setup.exe, tv.exe
Run tv.exe
}
but tv.exe is downloaded and installed even if it is installed already
swagfag
Posts: 1200
Joined: 11 Jan 2017, 17:59

Re: Check if file exist in any of two places and run it

Post by swagfag » 22 May 2018, 09:48

in an expression, anything enclosed in double quotes is regarded as literal text.
Post Reply

Return to “Ask For Help”