How can I tell whether the user launched my console application by double-clicking the EXE (or a shortcut), or whether they already had a command line window open and executed my console app within that session?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
You can find out what the parent process is:
Where Parent() is an extension method, e.g.:
You might be able to figure it out by P/Invoking to the Win32 GetStartupInfo() function.
Stick this static field in your "
Program
" class to ensure it runs before any output:This is a little bit overkill/paranoid, but picks up being started from Explorer while not responding to things like
cls && app.exe
(by checking for the full path) or evencls && "f:\ull\path\to\app.exe"
(by looking at the title).I got the idea from the win32 version of this question.