diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-08-21 13:36:15 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-08-21 13:36:15 +0000 |
commit | cc3503abc4e465c6d5c57a6e60716dafe0703aa5 (patch) | |
tree | 36e014fb4e4fc5ae75944f5c3a98d2b0407844ea /win | |
parent | 2fdfbe85d38ee2f83e86c67f94af2e7e7efb3b9f (diff) |
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
Diffstat (limited to 'win')
-rw-r--r-- | win/win32service.cpp | 31 |
1 files changed, 23 insertions, 8 deletions
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[] =
|