There may be an easier way, but the only way I can come up with is to check the name of the parent process, which includes several steps:
Keep in mind that the parent process may already disappear when (or for now) you complete this check.
Edit:
If your program is a console application, you can also check the console in which it is running. If it was launched from cmd, it will usually use the same console. So, you can use GetConsoleTitle , and see if it is a Command Prompt. This may not work in localized or different versions of Windows, but it is easy if you have limited cases. You can also use GetConsoleWindow and GetWindowThreadProcessId instead of steps 1 and 2.
source share