我正在尝试在隐藏的桌面上启动应用程序,但没有取得多大进展,也无法找到有关桌面和窗口站实际情况的详细文档。这是删除了错误处理的代码(但是我相信它并没有发现任何错误):
HWINSTA winSta = CreateWindowStation(_T("hiddenWinSta"), 0, 0, NULL);
SetProcessWindowStation(winSta);
HDESK desktop = CreateDesktop(_T("hiddenDesktop"), NULL, NULL, 0, DESKTOP_CREATEWINDOW, NULL);
OpenDesktop(_T("hiddenDesktop"), 0, TRUE, GENERIC_ALL);
SetThreadDesktop(desktop)
HWINSTA r = GetProcessWindowStation();
printf("winsta: %x %x\n", r, winSta);
HDESK curdesk = GetThreadDesktop(GetCurrentThreadId());
printf("desktop: %x %x\n", curdesk, desktop);
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
//si.lpDesktop = _T("hiddenDesktop");
ZeroMemory( &pi, sizeof(pi) );
TCHAR szCommand[MAX_PATH];
_sntprintf_s(szCommand, MAX_PATH, _T("%s"), _T("c:\\windows\\system32\\calc.exe"));
DWORD res = CreateProcess(NULL, szCommand, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
如果我取消注释si.lpDesktop行,则进程无法以可怕的错误0x000142启动。如果我评论si.lpDesktop进程在当前桌面上启动。 我究竟做错了什么?甚至可以做我想做的事情(即启动一个完全不可见的Windows GUI应用程序)?
答案 0 :(得分:1)
取消注释
si.lpDesktop = _T("hiddenDesktop");
评论
// HWINSTA winSta = CreateWindowStation(_T("hiddenWinSta"), 0, 0, NULL);
// SetProcessWindowStation(winSta);