Why is ShellExecuteEx failing with SE_ERR_NOASSOC for an EXE file?

Randy P 1 Reputation point
2022-05-07T03:36:15.46+00:00

I have a C application that does the following on Windows 2016 Server...

  1. It creates a new folder
  2. It copies an EXE file to the new folder (this copied EXE is also a C application)
  3. It runs the copied EXE using ShellExecuteEx

This process works 95% of the time but 5% of the time ShellExecuteEx fails with SE_ERR_NOASSOC (#31).

The application performs a few retries with a 30 second delay between each retry but ShellExecuteEx still fails with SE_ERR_NOASSOC.

Only after a FEW MINUTES does ShellExecuteEx work ok and run the EXE.

I have checked on-line for ShellExecuteEx and SE_ERR_NOASSOC issues but there is nothing related to EXE files.

I do not understand how it is even possible to get an SE_ERR_NOASSOC (ie. file association error) on an EXE file since it really does not have or need an association.

I thought that maybe Windows Defender was temporarily quarantining the recently copied EXE file until it has been scanned but I would expect a different error such as ERROR_FILE_NOT_FOUND or SE_ERR_ACCESSDENIED, but certainly note SE_ERR_NOASSOC.

Any assistance debugging this strange issue would be appreciated!

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,512 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,629 questions
{count} votes