I'm looking for a Win32 API call to return the runtime context of my process. I want to be able to programmatically test whether I am running as a service or running as a standard application process.
A few ideas come to mind ... Since I always have the DAD.exe service, which sometimes runs SON.exe as its child, and in the context of the service --- and sometimes SON.exe is launched not by DAD, but by the user.
SON.EXE will run the whoami () API to find out in what context it works.
Now DAD can create a var environment - and then SON can check this var - and if it finds out that it knows that it is the son of DAD and thus works as a service ..... But this is weak ..
Another idea is to look at my SID or token and see if I can make this determination .... Again, this looks best harder against one API check ...
source share