No announcement yet.

determine how program is started

  • Filter
  • Time
  • Show
Clear All
new posts

  • determine how program is started

    is there a way to determine how a program is started.
    batch, shell,etc.
    when a program is called from another program, it would be nice to be able to run the program being called in a quiet mode(no display) or from a batch program.

    i could not find anything and never read about anything on this.
    any help please
    p purvis

  • #2
    You might have luck using the startupinfo structure.


    See for processexplorer, they somehow detect the parent app.


    • #3
      The PROCESSENTRY32 structure which you get with Process32First/Next includes a ThParentProcessID member. That might help.

      If the parent process ID tracks back to CMD.EXE, it must be either a batch (command) file or a command prompt; if a program file, that's the parent process (SHELL, CreateProcess or ShellExecute[Ex]), if NULL it has no parent.
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]


      • #4
        it these are programs written by you then can't you just use SHELL to start the second program and pass the appropriate WndStyle or CommandString parameter to the called program?



        • #5
          You could always have your program take a commandline parameter so the program trying to open it has to pass a parameter that says how it was opened.

          (although this is still open to the commandline telling the truth as to what opened it, rather than lying, and say "Shell" when it was done by "CreateProcess", but still this is a simple way to know)

          MCM mentioned:
          The PROCESSENTRY32 structure which you get with Process32First/Next includes a ThParentProcessID member. That might help.
          hmmmmm....I am quite interested in this idea...and will have to research it.

          Edwin mentioned:
          See SysInternals for processexplorer, they somehow detect the parent app.
 NOT attempt to replicated what they do but rather use the tool provided if it helps. (This tool has saved me MANY times, but I would recommend not attempting to replicate because to my knowledge, the hardest parts are all beyond PB compiler the machine driver level)
          I think MCM nearly popped a mental cork warning me about extreme concepts, and the time invested vs what you get out of it. (in this one case it was worth it to me because it was like a puzzle I could not solve, but was helldriven to not let it beat me).

          (but if you insist on trying to nail it down, then these links will help

          Pierre Bellisle, was INSTRUMENTAL in assisting me along the way, as he was doing similar and posted his code in the old source code forum that I found under NtQuerySystemInformation with %SystemHandleInformation
          and I in turn improved as I could for the code I was working on at the time at Enum Handles with NtQuerySystemInformation (improved)

          We also included discussion with all those who helped, or provided input from discussions at Process Handles? via NtDll or PsApi?

          so if you decide to take it a step further...please be kind and post beyond what we tried...but I will warn you, unless you are willing to try, try, try may be a fruitless attempt.

          Good luck, and I am sure we will all be here to assist where we can.
          Engineer's Motto: If it aint broke take it apart and fix it

          "If at 1st you don't succeed... call it version 1.0"

          "Half of Programming is coding"....."The other 90% is DEBUGGING"

          "Document my code????" .... "WHYYY??? do you think they call it CODE? "


          • #6
            Thank you all very much for your responses and showing me the way.

            I write mostly console programs and try my best to think if somebody else or myself were to be using my exe program, and how would that person want to use the program if called from a batch file file or other program. Many of these programs return a value based on results, and a lot of programs do not need to display information when managed by a batch file or called by a program, even thought it is nice to have displayed information when executing a program not from a batch or another exe program.
            I makes it much easier for anybody to interface to a program and not have any text displayed messing with an calling routine.
            I will return any helpfully information find.
            paul purvis

            that program from sysinternals would come in helpful, but i was really thinking about a program that is running, determining its own condition of what means it was started under.
            Last edited by Paul Purvis; 29 Oct 2007, 01:55 AM.
            p purvis


            • #7
              If the user has to build a command line anyway......

              ..add a command-line "Quiet Mode" flag? e.g "MyApp.exe /q {rest of params}?"
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]