I have this code:
#define _WIN32_WINNT 0x0500
#include <cstdlib>
#include <iostream>
#include <windows.h>
using namespace std;
int main(int argc, char *argv[])
{
HDESK hOriginalThread;
HDESK hOriginalInput;
hOriginalThread = GetThreadDesktop(GetCurrentThreadId());
hOriginalInput = OpenInputDesktop(0, FALSE, DESKTOP_SWITCHDESKTOP);
HDESK hNewDesktop=CreateDesktop("BasicAppDesktopDesktop",NULL,NULL,0,DELETE|READ_CONTROL|WRITE_DAC|WRITE_OWNER|GENERIC_ALL,NULL);
/*HDESK hNewDesktop=OpenDesktop("Winlogon", 0, FALSE,
DESKTOP_CREATEMENU |
DESKTOP_CREATEWINDOW |
DESKTOP_ENUMERATE |
DESKTOP_HOOKCONTROL |
DESKTOP_JOURNALPLAYBACK |
DESKTOP_JOURNALRECORD |
DESKTOP_READOBJECTS |
DESKTOP_SWITCHDESKTOP |
DESKTOP_WRITEOBJECTS);
*/
SetThreadDesktop(hNewDesktop);
SwitchDesktop(hNewDesktop);
//system("cmd");
STARTUPINFOA si = {0};
si.cb = sizeof(STARTUPINFO);
si.lpDesktop = "winsta0\\BasicAppDesktopDesktop";
PROCESS_INFORMATION infos;
CreateProcess(NULL,"explorer",NULL,NULL,false,NORMAL_PRIORITY_CLASS,NULL,NULL,&si,&infos);
//WaitForSingleObject( infos.hProcess, INFINITE );
while(!(GetAsyncKeyState(VK_F12) == -32767))Sleep(50);
CloseHandle( infos.hProcess );
CloseHandle( infos.hThread );
SwitchDesktop(hOriginalInput);
SetThreadDesktop(hOriginalThread);
CloseDesktop(hNewDesktop);
CloseDesktop(hOriginalInput);
return 0;
}
When I press F12, desktop switch to original and program will close, but if I run in second desktop any program, then do not terminates, and when I run my program again, that any program will appears. Is there a way to delete desktops with programs, or automatic terminations of programs ran through second desktop on exit? Please help.