[fpc-pascal] Re: Can a program find out how it was started?

Jeff Miller miller at psy.otago.ac.nz
Thu Aug 4 06:55:57 CEST 2005

> > > > Is it possible for a program to tell whether it was started 
> > > > from the command line or started by double-clicking on the 
> > > > application icon?
> If you want to use Win API calls, I think 
> this would be a better (and simpler) way to do it:
> {===========================}
> program contest;
> uses windows;
> var
>   info:tSTARTUPINFO;
> begin
>   GetStartupInfo(@info);
>   if ( info.hStdInput = 0 ) 
>   then {Started from Explorer} 
>   else {Started from Console}
> end.
> {===========================}

This looks really attractive, but it doesn't work.
I get the same value of info.hStdInput (4294967295)
whether I run the program from the console or explorer.

So far I have been unable to find any information
on the fields of tSTARTUPINFO, so I can't figure out
how to elaborate on this idea.  (Google gives lots of hits, but they all
just seem to use tSTARTUPINFO, not to document it.)
If you have any further guidance on that, I'd appreciate it.

Thanks for your efforts, in any case.

Jeff Miller

More information about the fpc-pascal mailing list