I'm developing a win service in using mingw
I've been trying for hours
I looked for examples on the internet I used ChatGPT
and nothing it returned works and the few examples I found
had nothing to do with what I wanted
I hope there is some way to do this the
idea and before i create the SERVICE_TABLE_ENTRY
i can check if my executable was started
for a windows service,
if yes i create the
SERVICE_TABLE_ENTRY
if I don't do anything else.
CodePudding user response:
If your program supports multiple modes then I would suggest using a command line parameter like /service
for the service registration.
Alternatively you could check if your process token contains S-1-5-6
(SECURITY_SERVICE_RID) but I'm not sure which Windows version that was introduced.
CodePudding user response:
I saw a simple way to check this just create SERVICE_TABLE_ENTRY and use StartServiceCtrlDispatcher if it returns an error probably the executable was started like a normal program.
SERVICE_TABLE_ENTRY _dispatcher_entry_table[] =
{
{"", (LPSERVICE_MAIN_FUNCTION)serviceMain},
{NULL, NULL}
};
if (StartServiceCtrlDispatcher(_dispatcher_entry_table))
{
//probably a normal program
}