-1

I am working on a feasibility task, where I need to start an application in a custom desktop (programmatically created desktop, using CreateDesktop()).

Scenario:

ConsoleTestApplication: Use ShellExecute() to start an MFC application, LaunchingApp

LaunchingApp: Creates a new custom desktop and start a WPF application using ShellExecute(). The WPF application should open in the custom desktop.

The above scenario works while using CreateProcess(). When I tried with ShellExecute(), the custom desktop just glitched away, and didn't work.

Does ShellExecute() work along with custom desktop creation?

Is there any possible way to solve the above scenario using ShellExecute()? Can you suggest a solution for this?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • 2
    Why do you need to use `ShellExecute` when you can call `CreateProcess`? Why do you assume that `ShellExecute` is a vital part of the solution? – IInspectable Feb 01 '22 at 18:41
  • `ShellExecute` should never be used. `ShellExecuteEx` is for executing shell verbs. `CreateProcess` is for creating processes. – David Heffernan Feb 01 '22 at 19:42

1 Answers1

1

Neither ShellExecute() nor ShellExecuteEx() support launching processes on alternative desktops, only on the desktop of the calling thread.

So, you would have to either use SetThreadDesktop() before ShellExecute/Ex(), or else just use CreateProcess() instead, which supports alternative desktops, as you noted.

ShellExecute/Ex() will simply delegate to CreateProcess() when launching an EXE file, so you really should just use CreateProcess() directly. Use ShellExecute/Ex() only when launching data files (or when you need to force an EXE to launch with UAC elevation).

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770