Can anyone help me out with abit of code that will detect the location of any exe file on a hard drive / cd?
am trying to build a simple exe launcher thanks.
A few practical pointers that build on ’s and ’s comments and avoid the “app locks up” problem.
For a game launcher you should try cheap/fast sources first (avoid full-drive brute force until necessary): query the App Paths registry key for the EXE name, look at the Uninstall keys or vendor manifests (Steam/GOG/Epic often record install locations), and scan the usual folders (Program Files, Program Files (x86), Steam library paths). Only if those fail, fall back to a filesystem search. The UI freeze you saw is almost always because the search ran on the main thread — move any long I/O to a worker thread, and provide cancel/progress.
Example: quick registry check (returns full path from App Paths if present)
function FindExeInAppPaths(const ExeName: string): string;
var
Reg: TRegistry;
Key: string;
begin
Result := '';
Reg := TRegistry.Create(KEY_READ);
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
Key := 'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\' + ExeName;
if Reg.OpenKeyReadOnly(Key) then
Result := Reg.ReadString(''); // default value is full path
finally
Reg.Free;
end;
end; If you need a recursive search, run it in a thread and check Terminated frequently. This example uses TSearchRec and TThread; it synchronizes found results to the UI and supports cancellation.
type
TFileFoundEvent = procedure(const APath: string) of object;
TFileSearchThread = class(TThread)
private
FRoot, FPattern, FLastFound: string;
FOnFound: TFileFoundEvent;
procedure FoundSync;
protected
procedure Execute; override;
public
constructor Create(const ARoot, APattern: string; AOnFound: TFileFoundEvent);
end; Practical tips: skip unreadable/system folders, skip empty CD drives (check drive type), throttle UI updates (use TThread.Queue or batch updates) and test the search on a small folder first. On 64-bit Windows remember registry redirection: a 32-bit process may need to read the 64-bit view to find installer keys. These steps should let you build a responsive launcher that locates most game EXEs without freezing the UI.
Jump to Post— SalmiSoft 102If all you want to do is to launch the app then the easiest way is not to find it at all. Just lauch the EXE without specifying its path (for example, Notepad.exe rather than c:\blah\blah\blah\Notepad.exe) and let the OS find it for you. If the EXE is in your …
If all you want to do is to launch the app then the easiest way is not to find it at all. Just lauch the EXE without specifying its path (for example, Notepad.exe rather than c:\blah\blah\blah\Notepad.exe) and let the OS find it for you. If the EXE is in your path this should work and is worth a try to avoid a possible delay whilst you search for the exe.
If you do have to search for the EXE just remember that an EXE is just a file so you could to use FindFirst and FindNext to locate it. There are many examples out there. A reasonable place to start is http://stackoverflow.com/questions/5991040/how-to-search-different-file-types-using-findfirst
Ya I done that mate but this is for searching for game .exes and not everyone installs there games to same folder so need way to find the files I checked out the link you shared and tried it out but dont seam to work it locks up my test app.
Post the code you tried.
its ok I find a other way around it thanks for the help mate
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.