Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sherief/a95fd51e8afac1ad461dd5628e653bab to your computer and use it in GitHub Desktop.
Save sherief/a95fd51e8afac1ad461dd5628e653bab to your computer and use it in GitHub Desktop.
#include <windows.h>
#include <wtsapi32.h>
HANDLE CreateProcessActiveConsole(LPCTSTR app, LPTSTR cmd)
{
static HANDLE hToken;
static STARTUPINFO si;
static PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
WTSQueryUserToken(WTSGetActiveConsoleSessionId(), &hToken);
CreateProcessAsUser(hToken, app, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
return pi.hProcess;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment