1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| BOOL VistaStartProcess(IN PSTR pCmdLine) { if (pCmdLine == NULL) return FALSE; DWORD dwSessionId = WTSGetActiveConsoleSessionId(); if (dwSessionId == 0xFFFFFFFF) return FALSE; HANDLE hToken = NULL; if (!WTSQueryUserToken(dwSessionId, &hToken)) return FALSE; if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &hToken)) return FALSE; HANDLE hTokenDup = NULL; if (!DuplicateTokenEx(hToken, MAXIMUM_ALLOWED, NULL, SecurityIdentification, TokenPrimary, &hTokenDup)) { CloseHandle(hToken); return FALSE; } if (!SetTokenInformation(hTokenDup, TokenSessionId, &dwSessionId, sizeof(DWORD))) { CloseHandle(hTokenDup); CloseHandle(hToken); return FALSE; } CloseHandle(hToken); LPVOID pEnv = NULL; DWORD dwCreationFlags = NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE; if (CreateEnvironmentBlock(&pEnv, hTokenDup, TRUE)) dwCreationFlags |= CREATE_UNICODE_ENVIRONMENT; else pEnv = NULL; STARTUPINFO si = { 0 }; si.cb = sizeof(STARTUPINFO); si.lpDesktop = "winsta0\\default"; PROCESS_INFORMATION pi = { 0 }; if (!CreateProcessAsUser(hTokenDup, NULL, pCmdLine, NULL, NULL, FALSE, dwCreationFlags, pEnv, NULL, &si, &pi)) { if (pEnv != NULL) DestroyEnvironmentBlock(pEnv); CloseHandle(hTokenDup); return FALSE; } if (pEnv != NULL) DestroyEnvironmentBlock(pEnv); CloseHandle(hTokenDup); return TRUE; }
|