]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
detect if the process has an interactive session (if its started as a service, the...
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Thu, 21 Aug 2008 13:36:15 +0000 (13:36 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Thu, 21 Aug 2008 13:36:15 +0000 (13:36 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10199 e03df62e-2008-0410-955e-edbf42e46eb7

win/win32service.cpp

index ca44019c05205c9c42973630962259d7ce368cd0..0f8a2010806f8eac9edaf137c79d31a1412b4691 100644 (file)
@@ -27,8 +27,18 @@ static int serviceCurrentStatus;
 // This is used to define ChangeServiceConf2() as we can't link\r
 // directly against this symbol (see below where it is used)\r
 typedef BOOL (CALLBACK* SETSERVDESC)(SC_HANDLE,DWORD,LPVOID);\r
+\r
+/* A commandline parameter handler for service specific commandline parameters */\r
 typedef void (*CommandlineParameterHandler)(void);\r
 \r
+/* Represents a commandline and its handler */\r
+struct Commandline\r
+{\r
+       const char* Switch;\r
+       CommandlineParameterHandler Handler;\r
+};\r
+\r
+\r
 SETSERVDESC ChangeServiceConf;         // A function pointer for dynamic linking tricks\r
 \r
 \r
@@ -256,12 +266,6 @@ void RemoveService()
        CloseServiceHandle(scm);\r
 }\r
 \r
-struct Commandline\r
-{\r
-       const char* Switch;\r
-       CommandlineParameterHandler Handler;\r
-};\r
-\r
 /* In windows, our main() flows through here, before calling the 'real' main, smain() in inspircd.cpp */\r
 int main(int argc, char** argv)\r
 {\r
@@ -299,18 +303,29 @@ int main(int argc, char** argv)
                {\r
                        /* Service not installed or no permission to modify it */\r
                        CloseServiceHandle(scm);\r
-                       smain(argc, argv);\r
+                       return smain(argc, argv);\r
                }\r
        }\r
        else\r
        {\r
                /* Not enough privileges to open the SCM */\r
-               smain(argc, argv);\r
+               return smain(argc, argv);\r
        }\r
 \r
        CloseServiceHandle(myService);\r
        CloseServiceHandle(scm);\r
 \r
+       /* Check if the process is running interactively. InspIRCd does not run interactively\r
+        * as a service so if this is true, we just run the non-service inspircd.\r
+        */\r
+       USEROBJECTFLAGS uoflags;\r
+       HWINSTA winstation = GetProcessWindowStation();\r
+       if (GetUserObjectInformation(winstation, UOI_FLAGS, &uoflags, sizeof(uoflags), NULL))\r
+       {\r
+               if (uoflags.dwFlags == WSF_VISIBLE)\r
+                       return smain(argc, argv);\r
+       }\r
+\r
        /* If we get here, we know the service is installed so we can start it */\r
 \r
        SERVICE_TABLE_ENTRY serviceTable[] =\r