# Files associated to which program?

**URL:** <https://clarionhub.com/t/files-associated-to-which-program/9025>\
**Category:** questions\
**Tags:** winapi\
**Created:** [April 2, 2026, 10:07pm UTC](https://clarionhub.com/t/files-associated-to-which-program/9025 "2026-04-02T22:07:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jorge\_Alejandro\_Lave](https://clarionhub.com/user_avatar/clarionhub.com/jorge_alejandro_lave/32/6482_2.png) [@Jorge\_Alejandro\_Lave](https://clarionhub.com/u/Jorge_Alejandro_Lave)\
**Post date:** [April 2, 2026, 10:07pm UTC](https://clarionhub.com/t/files-associated-to-which-program/9025/1 "2026-04-02T22:07:11Z")

</div>

Hi, all

How do I know from inside a regular non-elevated exe clarion program, to which program is associated a given file extension? For example, I want to use Shellexecute to open a JPG, but before that I want to know if the JPG extension is associated with MSPaint or any other program, to execute different code previous to the call.

Kind regards,  
Jorge Lavera

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [April 3, 2026, 12:14am UTC](https://clarionhub.com/t/files-associated-to-which-program/9025/2 "2026-04-03T00:14:19Z")

</div>

FindExecutable

Search for that and read MSDN there are other ways

> **[FindExecutableA function (shellapi.h) - Win32 apps](https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-findexecutablea)**
>
> Retrieves the name of and handle to the executable (.exe) file associated with a specific document file. (ANSI)

> **[Why does FindExecutable behave erratically for files with extensions longer...](https://devblogs.microsoft.com/oldnewthing/20160408-00/?p=93274)**
>
> Short file names strike again.

```c
HINSTANCE FindExecutableA(
  [in] LPCSTR lpFile,
  [in, optional] LPCSTR lpDirectory,
  [out] LPSTR lpResult
);

```

This should be close for Clarion map

```clarion
FindExecutable PROCEDURE( |
       *CSTRING lpFile, |
      <*CSTRING lpDirectory>, |
       *CSTRING OutResult |
       ),LONG,PASCAL,RAW,DLL(1),NAME('FindExecutableA') ! Returns HINSTANCE >=33 indicates Success

```

Error 31 for No Assoc seems likely. There’s are the same as Shell Execute

```clarion
SE_ERR_FNF Equate(2) !The specified file was not found.
SE_ERR_PNF Equate(3) !The specified path is invalid.
SE_ERR_ACCESSDENIED Equate(5) !The specified file cannot be accessed.
SE_ERR_OOM Equate(8) !The system is out of memory or resources.
SE_ERR_NOASSOC Equate(31) !There is no association for the specified file type with an executable file.

```

---

<div class="post-metadata">

**Author:** ![RchdR](https://clarionhub.com/letter_avatar_proxy/v4/letter/r/d78d45/32.png) [@RchdR](https://clarionhub.com/u/RchdR)\
**Post date:** [April 3, 2026, 8:12am UTC](https://clarionhub.com/t/files-associated-to-which-program/9025/3 "2026-04-03T08:12:54Z")

</div>

> **[Guidelines for File Associations and Default Programs - Win32 apps](https://learn.microsoft.com/en-us/windows/win32/shell/appguide-fa-defpro)**
>
> This section on application guidelines for file associations and default programs is organized as follows:

> **[Managing Default Applications - Win32 apps](https://learn.microsoft.com/en-us/windows/win32/shell/vista-managing-defaults)**
>
> This topic provides independent software vendors (ISVs) with a quick guide to the steps necessary to register and manage application defaults in Windows Vista and later. Links are provided to more in-depth articles about each section's topic.

---

<div class="post-metadata">

**Author:** ![Jorge\_Alejandro\_Lave](https://clarionhub.com/user_avatar/clarionhub.com/jorge_alejandro_lave/32/6482_2.png) [@Jorge\_Alejandro\_Lave](https://clarionhub.com/u/Jorge_Alejandro_Lave)\
**Post date:** [April 3, 2026, 2:12pm UTC](https://clarionhub.com/t/files-associated-to-which-program/9025/4 "2026-04-03T14:12:54Z")

</div>

Thank you! that worked perfectly.

This is in a legacy program.  
In the global embeds, inside the global map:

```clarion
    MODULE('shell32.dll')
        FindExecutableA(*cstring,*cstring,*cstring),LONG, PASCAL, RAW, NAME('FindExecutableA')
    END

```

Several sources recommend to use FindExecutableW instead of FindExecutableA, don’t bother, it doesn’t work with Clarion.  
You will need some local variabes:

```clarion
l:File CSTRING(2049)
l:Directory CSTRING(2049)
l:Result CSTRING(2049)
L:Executable STRING(256)
L:Status LONG

```

And, assign your variables to the call:

```clarion
L:File = clip(YourfFlenameOnly)
L:directory = clip(YourPathOnly)
L:Status = FindExecutableA(L:File,L:Directory,L:Result) 
L:Executable = st.FilenameOnly(L:Result)

```

I used Capesoft’s StringTheory to quickly get the filename only, from the result, as it is returned with fully path. You can, of course, use your own code or other tool for that.

That’s it!  
Then you can, for example:

```clarion
if lower(clip(L:Executable)) = 'mspaint.exe' then
    !Do whatever
end

```

Kind regards,  
Jorge Lavera

---

<div class="post-metadata">

**Author:** ![RchdR](https://clarionhub.com/letter_avatar_proxy/v4/letter/r/d78d45/32.png) [@RchdR](https://clarionhub.com/u/RchdR)\
**Post date:** [April 3, 2026, 5:22pm UTC](https://clarionhub.com/t/files-associated-to-which-program/9025/5 "2026-04-03T17:22:18Z")

</div>

> [@Jorge\_Alejandro\_Lave](#):
>
> Several sources recommend to use FindExecutableW instead of FindExecutableA, don’t bother,

The W affix/suffix is used to denote Wide Char aka Unicode, and the A is used to denote Ansi aka Windows Code Page.

> **[Conventions for Function Prototypes - Win32 apps](https://learn.microsoft.com/en-us/windows/win32/intl/conventions-for-function-prototypes)**
>
> The Windows SDK provides function prototypes in generic, Windows code page, and Unicode versions.

Most of the time you’ll be using A suffix API’s, but some Windows API’s only exist in a W suffix form, so besides using that W suffix API you’ll also have to use API’s to convert the Unicode string back to Ansi and vice versa as described here:

> **[Converting Unicode and ANSI Strings - Win32 apps](https://learn.microsoft.com/en-us/windows/win32/winauto/converting-unicode-and-ansi-strings)**
>
> Microsoft Active Accessibility uses Unicode strings as defined by the BSTR data type.

Dot Net is similiar with the A & W suffixes.

> **[Breaking change: No A/W suffix probing on non-Windows platforms - .NET](https://learn.microsoft.com/en-us/dotnet/core/compatibility/interop/5.0/function-suffix-pinvoke)**
>
> Learn about the interop breaking change in .NET 5 where suffixes are no longer added to function export names during probing for P/Invokes on non-Windows platforms.

> In previous versions of .NET, both the CoreCLR and Mono runtimes add an A or W suffix to the export name during export discovery for P/Invokes on all platforms.
> 
> In .NET 5 and later versions, an A or W suffix is added to the export name during export discovery on Windows only. On Unix platforms, the suffix is not added. The semantics of both runtimes on the Windows platform remain unchanged.

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [April 3, 2026, 7:46pm UTC](https://clarionhub.com/t/files-associated-to-which-program/9025/6 "2026-04-03T19:46:53Z")

</div>

> [@Jorge\_Alejandro\_Lave](#):
>
> ```auto
> l:Result CSTRING(261)
> L:Executable STRING(260)
> 
> L:Status = FindExecutableA(L:File,L:Directory,L:Result) 
> L:Executable = st.FilenameOnly(L:Result)
> 
> ```
> 
> I used Capesoft’s StringTheory to quickly get the filename only, from the result, as it is returned with fully path. You can, of course, use your own code or other tool for that.

The File Name is simply after the Last Backslash, if there is one.

It’s not well known but `INSTRING(,,-1,End Len)` can search in Reverse with a Step of -1 and Start at the End of the String i.e. its `SIZE()` or `LEN()`. Code below finds the Last Backslash.

```clarion
    L:Executable = L:Result
    LastBS=INSTRING('\',L:Executable,-1,SIZE(L:Executable)) !Find \program.exe after c:\path
    L:Executable=SUB(L:Executable,LastBS+1,999)

```

For a `CSTRING` the `LEN()` is correct to avoid possible garbage after the `Chr(0)` that `SIZE()` would search:

```clarion

    LastBS=INSTRING('\',L:Result,-1,LEN(L:Result)) !Find \program.exe after c:\path
    L:Executable=SUB(L:Result,LastBS+1,999)

```
