void () { if (!myFailureDetected) { try { // This might not work in all cases, but hopefully is a more reliable method than the current one (checking for font smoothing) // see https://msdn.microsoft.com/en-us/library/aa380798%28v=vs.85%29.aspx myRemoteDesktopConnected = User32.INSTANCE.GetSystemMetrics(0x1000) != 0; // 0x1000 is SM_REMOTESESSION LOG.debug("Detected remote desktop: ", myRemoteDesktopConnected); } catch (Throwable e) { myRemoteDesktopConnected = false; myFailureDetected = true; LOG.warn("Error while calling GetSystemMetrics", e); } } }