-1

If I have a file path (that might be later passed to the ShellExecute API) is there any way to tell if it points to an application?

I need this to work under Windows from a C++ program. Also, this path may contain start-up command line parameters.

Ry-
  • 218,210
  • 55
  • 464
  • 476
ahmd0
  • 16,633
  • 33
  • 137
  • 233
  • 1
    Define "application." That word spans many different types of files. – Carey Gregory Dec 12 '11 at 05:55
  • Yes, good point. Application path is a path to a file that can represent a process in a Windows kernel architecture. – ahmd0 Dec 12 '11 at 07:48
  • 1
    It's really hard to define this. Do shortcuts count? Scripts? Documents (that, when double-clicked, open applications)? – tenfour Dec 12 '11 at 14:42

2 Answers2

1

You can use the SaferiIsExecutableFileType function in order to check if the file is executable.

Norbert Willhelm
  • 2,579
  • 1
  • 23
  • 33
0

So you really want to know if a string that represents a command line has the path to an executable as its first "part". How you go about this kind of depends on how accurate you want the information to be.

First, you have to parse the string to get the first argument. It's not as simple as just looking for the first space, because Windows paths can contain spaces. You'll have to handle things like "c:\program files\internet explorer\iexplore.exe" "http://stackoverflow.com".

Searching for a file is a rather complicated process that involves searching the directories in the PATH environment variable. The SearchPath API function can help.

Jim Mischel
  • 131,090
  • 20
  • 188
  • 351
  • Yes, I agree that this doesn't seem as easy as it sounds. So in relation to SearchPath, OK, it's obvious if the extension is .exe, but as I pointed out below, what if the extension is missing? – ahmd0 Dec 12 '11 at 07:51
  • Read the documentation for `SearchPath`, specifically the `lpExtension` parameter. – Jim Mischel Dec 12 '11 at 14:25