Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There might be an easier way, but the only way I can think of is to check the parent process name, which involves a few steps:</p> <ol> <li><a href="https://stackoverflow.com/questions/185254/how-can-a-win32-process-get-the-pid-of-its-parent">Get the ID of the parent process</a>.</li> <li><a href="https://stackoverflow.com/questions/2221103/how-to-get-process-handle-from-process-id">Get the handle of the process</a>, using the ID.</li> <li>Use <a href="http://msdn.microsoft.com/en-us/library/ms683198%28VS.85%29.aspx" rel="nofollow noreferrer">GetModuleFileNameEx</a> with the handle found (and NULL as the module) to get the executable's name.</li> <li>Check if the executable's name is cmd.exe or whatever.</li> </ol> <p>Bear in mind that the parent process might already be gone when (or while) you do this check.</p> <p>Edit:</p> <p>If your program is a console application, you can also check the console it's running in. If it was run from cmd, it will usually use the same console. So, you can use <a href="http://msdn.microsoft.com/en-us/library/ms683174%28v=vs.85%29.aspx" rel="nofollow noreferrer">GetConsoleTitle</a>, for instance, and see if it's "Command Prompt". This might not work on localized or different versions of Windows, but it's easy if you have limitated cases. You can also use <a href="http://msdn.microsoft.com/en-us/library/ms683175%28v=vs.85%29.aspx" rel="nofollow noreferrer">GetConsoleWindow</a> and <a href="http://msdn.microsoft.com/en-us/library/ms633522%28VS.85%29.aspx" rel="nofollow noreferrer">GetWindowThreadProcessId</a> instead of steps 1 and 2.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload