Created
November 26, 2021 15:06
-
-
Save RigoLigoRLC/43b66292f639a8d05460ad92fa44cdbf to your computer and use it in GitHub Desktop.
Check if a CLI program is running inside Windows Terminal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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