65696

How to replicate ShellExecuteEx failure with ERROR_NO_ASSOCIATION error?

Question:

My application displays a report to its end-users by composing it into an .htm file that is placed into a user's temp folder (that is derived by calling GetTempPath API). It is then shown to the user with the code as such:

//strCmd == file:///C:/Users/UserName/AppData/Local/Temp/My_Report.htm SHELLEXECUTEINFO sei = {0}; sei.cbSize = sizeof(sei); sei.fMask = SEE_MASK_FLAG_NO_UI; sei.nShow = SW_SHOW; sei.lpVerb = L"open"; sei.lpFile = strCmd.GetBuffer(); sei.hwnd = hParentWnd; BOOL bInitialized = SUCCEEDED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE)); if(ShellExecuteEx(&sei)) { //Success } else { //Failed REPORT_ERROR(GetLastError()); } if(bInitialized) { CoUninitialize(); }

I just got a bug report from a customer that shows that the code above reports ERROR_NO_ASSOCIATION. The OS from the picture I got looks like Windows 8.1, or maybe Windows 7.

So I've been trying to replicate it in a VM by removing all file associations for the .htm and .html file extensions, but ShellExecuteEx never seems to fail. On Windows 10 it always opens up Edge and on Win 8.1 it showed this popup:

<a href="https://i.stack.imgur.com/8Q2OQ.png" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/8Q2OQ.png" data-original="https://i.stack.imgur.com/8Q2OQ.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

Does anyone know how I can replicate that error?

Answer1:

Removing .htm[l] probably has no effect because file:// is a protocol so you probably have to remove it as well.

You should try to remove HKCR\file.

This is as far as the documentation can take you but there are other undocumented keys involved in the default association selection.

For file extensions you need to remove HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.htm (or as a minimum, the UserChoice subkey)

and for protocols you need to remove HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\file. This key can exist under HKLM as well.

There might be other keys involved, you can find out where Windows looks by monitoring your application with Process Monitor from SysInternals.

Recommend

  • Default selected applet doesn't return right value
  • Response Object not returning Excel stream in update Panel?
  • Spurious '\\r' added by CRichEditCtrl::GetLine() when called on single-character lines?
  • A simple way to setting a bufferedImage into a single colored pixel without placing a image into it?
  • String or binary data would be truncated when uploading file in MVC
  • How to get the object reference of a field of an object using reflection?
  • How to change MKAnnotation Color using Swift?
  • Getting the activecontrol name and value from a multipages form
  • Silverlight DataGrid validation show validation error for all objects|properties
  • How to Get TCanvas DC in Firemonkey?
  • Hive command line Select query time taken incorrect if its not map reduce job in the background
  • C# Getting window's title by handle in Hebrew return question marks
  • “Undefined reference” trying to reference an static field
  • Extend Codeigniter Exceptions class to add a custom method
  • Google App Indexing not resolving for Swift?
  • getting empty value in viewWillAppear( ) but getting valid value in viewDidLoad( )
  • Pass a custom comparator through a function
  • C# Dictionary ContainsKey
  • How to map childs/parent class with petapoco?
  • Getting push notification payload when user opens app manually after push has been received in the b
  • Change color of row programmatically in WatchKit
  • Linked list in C, no member error
  • Conditional serialization with protobuf-net
  • Ambiguous action methods in MVC 2
  • Can someone explain the exact use of interfaces in C#?
  • Collect HostCPU utilisation and disk I/O speed using XenServer Java API
  • Auto Height of UICollectionView inside UITableViewCell
  • show window while in full screen
  • Member function pointer cast, from Derived to Base class
  • Window screenshot using WinAPI
  • Is the Go HTTP handler goroutine expected to exit immediately in this case?
  • how to save bool value in KeychainItemWrapper
  • Load 24 bit TGA
  • PHP file_exists() anomaly
  • Generate a unique string based on a pair of strings
  • Deleting a widget from QTableView
  • multidatatrigger with multibinding in ControlTemplate.Triggers
  • Is there a parser equivalent of 'fragment' marking in ANTLR4?
  • Need code translation from VB to C#
  • Build Successful but not running on simulator