From cc3503abc4e465c6d5c57a6e60716dafe0703aa5 Mon Sep 17 00:00:00 2001 From: brain Date: Thu, 21 Aug 2008 13:36:15 +0000 Subject: detect if the process has an interactive session (if its started as a service, the window station will have no drawable surfaces, and we can detect this) git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10199 e03df62e-2008-0410-955e-edbf42e46eb7 --- win/win32service.cpp | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'win') diff --git a/win/win32service.cpp b/win/win32service.cpp index ca44019c0..0f8a20108 100644 --- a/win/win32service.cpp +++ b/win/win32service.cpp @@ -27,8 +27,18 @@ static int serviceCurrentStatus; // This is used to define ChangeServiceConf2() as we can't link // directly against this symbol (see below where it is used) typedef BOOL (CALLBACK* SETSERVDESC)(SC_HANDLE,DWORD,LPVOID); + +/* A commandline parameter handler for service specific commandline parameters */ typedef void (*CommandlineParameterHandler)(void); +/* Represents a commandline and its handler */ +struct Commandline +{ + const char* Switch; + CommandlineParameterHandler Handler; +}; + + SETSERVDESC ChangeServiceConf; // A function pointer for dynamic linking tricks @@ -256,12 +266,6 @@ void RemoveService() CloseServiceHandle(scm); } -struct Commandline -{ - const char* Switch; - CommandlineParameterHandler Handler; -}; - /* In windows, our main() flows through here, before calling the 'real' main, smain() in inspircd.cpp */ int main(int argc, char** argv) { @@ -299,18 +303,29 @@ int main(int argc, char** argv) { /* Service not installed or no permission to modify it */ CloseServiceHandle(scm); - smain(argc, argv); + return smain(argc, argv); } } else { /* Not enough privileges to open the SCM */ - smain(argc, argv); + return smain(argc, argv); } CloseServiceHandle(myService); CloseServiceHandle(scm); + /* Check if the process is running interactively. InspIRCd does not run interactively + * as a service so if this is true, we just run the non-service inspircd. + */ + USEROBJECTFLAGS uoflags; + HWINSTA winstation = GetProcessWindowStation(); + if (GetUserObjectInformation(winstation, UOI_FLAGS, &uoflags, sizeof(uoflags), NULL)) + { + if (uoflags.dwFlags == WSF_VISIBLE) + return smain(argc, argv); + } + /* If we get here, we know the service is installed so we can start it */ SERVICE_TABLE_ENTRY serviceTable[] = -- cgit v1.2.3