简体   繁体   中英

Start a process in custom desktop with ShellExecute call

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?

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM