Skip to content

Instantly share code, notes, and snippets.

@3735943886
Created July 19, 2019 05:07
Show Gist options
  • Save 3735943886/258d473263c97591f3e557306a6291cc to your computer and use it in GitHub Desktop.
Save 3735943886/258d473263c97591f3e557306a6291cc 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