Page 1 of 1

Best way to find an executable

Posted: 22 Feb 2018, 16:51
by BGM
My script is a GUI for another program, but it needs to assure that the other program is installed, and needs to find the file path.

The program could be installed anywhere - c:\program files\thisapp, c:\program files (x86)\thisapp, c:\thisapp, etc.
However, it always resides in a folder with it's own application name, in my example here, "thisapp".
Sometimes it may also be an environmental variable.

What is the best approach to discovering it's location?
I want to add a sort of wizard that will locate the executable.

So far, all I can think of is to use FileLoop somehow and hope it doesn't take forever, or look in the most likely places and hope it's just there.

Re: Best way to find an executable

Posted: 22 Feb 2018, 17:29
by RickC
Have you tried a search loop through HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall? If the app writes an entry there then it should be easy to find its InstallLocation.

Have a look at https://autohotkey.com/docs/commands/LoopReg.htm#new for more info/examples.

Hope this helps...

Re: Best way to find an executable

Posted: 22 Feb 2018, 17:38
by BGM
The program in mind won't have an entry there - it uses an unconventional installer.

Re: Best way to find an executable

Posted: 22 Feb 2018, 20:11
by Masonjar13
The best efficiency method I can think of is to loop through the folders in the most likely places (start deeper and go up) (with recursion). So, check the folders in, say, program files, then if it's not there, check the next place. If all else fails, then you can do a system-wide search.

Alternatively, if it's already running, you can just grab the path from the processes command line info. Just prompt the user to run it, while constantly checking the processes, wait for it to exist, then grab it and continue.

Re: Best way to find an executable

Posted: 22 Feb 2018, 20:59
by jeeswg
- If it has a Start menu link, try searching in these folders:
A_StartMenu
A_StartMenuCommon
- Some programs store their full paths in the registry:
HKEY_CLASSES_ROOT\Applications
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
Best way to get the path to an executable - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 51#p168051