--- a/WinWorkstation.st Fri May 24 13:52:10 2019 +0200
+++ b/WinWorkstation.st Fri May 24 16:35:27 2019 +0200
@@ -15597,9 +15597,24 @@
"initialize the receiver for a connection to a display;
the argument, aDisplayName may be nil (for the default display)
or the name of the display server as hostname:number
- (not yet under WIN32)"
-
-%{ /* NOCONTEXT */
+ (not yet under WIN32)
+
+ Fetch the process session id before opening the display.
+ For Windows Vista and later the process session id is 0
+ in the case the process runs within service environment
+ if the process runs within logged-in user environment the session id is greater than 0,
+ see https://stackoverflow.com/questions/207896/c-net-detect-whether-program-is-being-run-as-a-service-or-a-console-applicati"
+
+%{ /* NOCONTEXT */
+ DWORD sessionId;
+
+ if (!ProcessIdToSessionId(GetCurrentProcessId(), &sessionId)) {
+ printf("ProcessIdToSessionId failed with %d\n", GetLastError());
+ };
+
+ if (sessionId == 0) {
+ RETURN ( __MKSMALLINT(0) );
+ }
RETURN ( __MKSMALLINT(1) );
%}.