Question How can I programmatically locate an EXE file's path?

Joined
Sep 16, 2023
Messages
24
Programming Experience
10+
WHAT I HAVE:
Visual Basic 2019, .NET Framework 4.6+, WinForms

MY ISSUE:

I would like my program to programmatically search for an exe file on my system drive and return its full path (so my program knows if and where it exists before trying to start the Process), but I've realized that the file is all but certain to be in a folder that one needs special permission to search (or a subfolder thereof)--i.e., "System", "Program Files", "Program Files (x86)"--complicating my efforts to use GetFiles/GetDirectories to look for it. Even trying do a single GetFiles method call on entire system drive with SearchOptions.AllDirectories causes an exception--and a targeted search within strategic folders (and their subfolders) causes many exceptions. Is there a (relatively) simple way for my app to programmatically obtain the necessary permissions for parent folders where program files are typically stored--or, better yet, a simple 1-step (or few-step) way to simply find the path of an arbitrary exe file? I want a VB.NET procedure that takes a String like ExeFile and returns a fully-qualified string for its entire path. Please give it to me ASAP in VB.NET, and as simply as possible.
 
The GetFiles method has been improved in .NET Core to be able to ignore exceptions on inaccessible folders but, as you're on .NET Framework, that's not an option, so you can't use GetFiles or the like for more than a single folder at a time. You have to write your own recursive file search code, so you can manually catch and then ignore those exceptions. There are plenty of examples already on the web so, rather than our providing another one here, I would suggest that you do a bit of searching and a bit of experimentation, then post back if you encounter any specific issue(s).
 
Back
Top