captmicro

WindowsStation/Background Desktops

May 31st, 2010
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.76 KB | None | 0 0
  1. HDESK hdReal;
  2. HDESK hdVirt;
  3. HWINSTA winStaReal;
  4. HWINSTA winStaVirt;
  5.  
  6. int WINAPI main(int argc, char *argv[])
  7. {
  8.     winStaReal = GetProcessWindowStation();
  9.     hdReal = GetThreadDesktop(GetCurrentThreadId());
  10.     winStaVirt = CreateWindowStationA("microsta2", 0, GENERIC_ALL, NULL);
  11.  
  12.     SetProcessWindowStation(winStaVirt);
  13.     hdVirt = CreateDesktopA("microdesk2", 0, 0, DF_ALLOWOTHERACCOUNTHOOK, GENERIC_ALL, 0);
  14.     SetProcessWindowStation(winStaReal);
  15.  
  16.     /*RunInVD(hdReal, hdVirt, "microdesk2", "C:\\Windows\\system32\\explorer.exe", NULL);
  17.     SwitchDesktop(hdVirt);
  18.     Sleep(1000 * 60);
  19.     SwitchDesktop(hdReal);*/
  20.    
  21.     RunInVD(hdReal, hdVirt, "microdesk2", "J:\\temp\\WinVNC.exe", NULL);
  22.     RunInVD(hdReal, hdVirt, "microdesk2", "J:\\temp\\WinVNC.exe", "-connect 127.0.0.1");
  23.  
  24.     CloseDesktop(hdVirt);
  25.     CloseWindowStation(winStaVirt);
  26.     getchar();
  27.     return 0;
  28. }
  29.  
  30. HANDLE RunInVD(HDESK real, HDESK vd, char *vdName, char *exe, char *args)
  31. {
  32.     char *cmdLine;
  33.     cmdLine = (char*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(char)*(lstrlenA(exe)+lstrlenA(args)+3));
  34.     lstrcpyA(cmdLine, exe);
  35.     if (args != NULL)
  36.     {
  37.         lstrcatA(cmdLine, " ");
  38.         lstrcatA(cmdLine, args);
  39.     }
  40.  
  41.     PROCESS_INFORMATION pi;
  42.     STARTUPINFO *si;
  43.     si = (STARTUPINFO*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(STARTUPINFO));
  44.     si->cb = sizeof(si);
  45.     si->lpDesktop = (char*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(char)*lstrlenA(vdName)+1);
  46.     lstrcpyA(si->lpDesktop, vdName);
  47.  
  48.     SetThreadDesktop(vd);
  49.     CreateProcessA(NULL, cmdLine, NULL, NULL, TRUE, 0, NULL, NULL, si, &pi);
  50.     SetThreadDesktop(real);
  51.  
  52.     if (si->lpDesktop != NULL) HeapFree(GetProcessHeap(), 0, si->lpDesktop);
  53.     if (si != NULL) HeapFree(GetProcessHeap(), 0, si);
  54.     HeapFree(GetProcessHeap(), 0, cmdLine);
  55.  
  56.     return pi.hProcess;
  57. }
Add Comment
Please, Sign In to add comment