Skip to content

Instantly share code, notes, and snippets.

@RigoLigoRLC
Created November 26, 2021 15:06
Show Gist options
  • Save RigoLigoRLC/43b66292f639a8d05460ad92fa44cdbf to your computer and use it in GitHub Desktop.
Save RigoLigoRLC/43b66292f639a8d05460ad92fa44cdbf to your computer and use it in GitHub Desktop.
Check if a CLI program is running inside Windows Terminal
#include <psapi.h>
#include <windows.h>
#ifdef _WIN32
int checkIsWinTerm()
{
HWND hConsoleWnd = GetConsoleWindow();
DWORD dwConsolePid;
GetWindowThreadProcessId(hConsoleWnd, &dwConsolePid);
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION,
FALSE,
dwConsolePid);
WCHAR imageName[MAX_PATH];
GetProcessImageFileNameW(hProcess, imageName, MAX_PATH);
return wcsicmp(imageName + wcslen(imageName) - 15, L"openconsole.exe");
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment