Related: Should I include a command line mode in my applications? How to grab parent process standard output? Can a console application dete
See Can a Win32 console application detect if it has been run from the explorer or not?
Or I think the official way is to check the parent process is cmd.exe or explorer.exe