Can a Win32 console application detect if it has been run from the explorer or not?

前端 未结 6 1117
误落风尘
误落风尘 2020-12-13 12:49

I have to create a console application which needs certain parameters. If they are missing or wrong I print out an error message.

Now the problem: If someone starts

6条回答
  •  不思量自难忘°
    2020-12-13 13:46

    I believe cmd.exe sets the CMDCMDLINE and CMDEXTVERSION environemntal variables when it starts. So if these are set your program was most probably started from a shell.

    This isn't foolproof but it's something.

    It's also possible to determine your parent PID in a few convoluted and possibly unreliable ways, or so I gather. You may want to look into that.

提交回复
热议问题