#StackBounty: #c++ #winapi #windows-services How to check that the current process is running as Windows Service using WinAPI functions?

Bounty: 50

I have a program that can be run as a simple console application or can be registered as Windows Service. I want to detect in main() function the current running context:

#include <windows.h>

BOOL IsWindowsService()

int main(int argc, char** argv)
    if (IsWindowsService())
        // Running as Windows Service...

    // Running as console application...    
    return 0;

Can you help me with a possible implementation of IsWindowsService() function?

Get this bounty!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.