0

I am creating new desktop from my C++ app and then switch to this desktop (by calling SetThreadDesktop) to create explorer process there. Then switch back to original desktop. The first problem is that I can't see this desktop in TaskView. And the second (and most important) problem is that I can't launch several applications (Google Chrome for example) or even open Start menu by pressing start button, but can start notepad for example. However if I create new desktop from task view then everything works fine. So the question is how to create new desktop from C++ application that will allow to create all processes and open start menu? Here is my code:

HDESK CreateDevTestDesktopW(const wchar_t* desktop_name)
{
    wchar_t explorer_path[MAX_PATH];
    HDESK original_desktop;
    HDESK devtest_desktop = NULL;
    STARTUPINFOW startup_info = { 0 };
    PROCESS_INFORMATION process_info = { 0 };
    ExpandEnvironmentStringsW(L"%windir%\\explorer.exe", explorer_path, MAX_PATH - 1);
    devtest_desktop = CreateDesktopW(desktop_name, NULL, NULL, 0, GENERIC_ALL, NULL);
    original_desktop = GetThreadDesktop(GetCurrentThreadId());
    if (SetThreadDesktop(devtest_desktop))
    {
        startup_info.cb = sizeof(startup_info);
        startup_info.lpDesktop = LPWSTR(desktop_name);

        CreateProcessW(explorer_path, NULL, NULL, NULL, FALSE, 0, NULL, NULL, &startup_info, 
&process_info);
        SetThreadDesktop(original_desktop);
    }

    return devtest_desktop;
}
rudolfninja
  • 467
  • 7
  • 24

1 Answers1

1

As @RaymondChen said, TaskView which manages virtual desktops uses IVirtualDesktop, IVirtualDesktopManager, IVirtualDesktopNotification, etc.
In order to Start an Interactive Client Process in C++, it's necessary to add access control entries (ACEs) to the discretionary access control list (DACL) of the interactive window station and desktop. Then calling the ImpersonateLoggedOnUser function to ensure that it has access to the client's executable file and the CreateProcessAsUser function creates the client's process. There is a related thread.

YangXiaoPo-MSFT
  • 1,589
  • 1
  • 4
  • 22