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

Marco van de Voort marcov at stack.nl
Wed Aug 3 14:55:35 CEST 2005

> Under Win98, there are some subtle differences in the output of the program
> below, when run from a DOS window  vs.  double-clicking the icon.
> I don't know if this will work for NT-based OS, though....
> {=====================}
> program envtest;
> uses Dos;
> var
>   F:text;
>   i:LongInt;
> begin
>   assign(F, 'envlist.txt');  
>   rewrite(F);
>   for i:=0 to EnvCount-1 do WriteLn(F, EnvStr(i));
>   close(F);
> end.
> {=====================}

I'd try to search the win32 api, and find a way to find the parent of my process,
either by a direct call, or enumerating all processes. And then check if it is cmd.exe or command.com or explorer.exe

More information about the fpc-pascal mailing list