It is useful to detect if running in a remote session to optimize visual effects or colors.
In Java, you need to use JNI (Java Native Interface) to call this Windows native API. Native Call is an Open Source project which provide an easy way to that.
http://johannburkard.de/software/nativecall/
All you need is 2 jars (nativecall-0,4,1.jar and nativeloader-200505172341.jar) plus 1 DLL (NativeCall.dll) in your classpath.
When running from Eclipse, the DLL should be in the bin directory of your application.
import java.io.IOException;
import com.eaio.nativecall.IntCall;
import com.eaio.nativecall.NativeCall;
public class WindowsUtils {
public static final int SM_REMOTESESSION = 4096; // remote session
private WindowsUtils() {}
public static boolean isRemote() throws SecurityException, UnsatisfiedLinkError,
UnsupportedOperationException, IOException
{
NativeCall.init();
IntCall ic = null;
try {
ic = new IntCall("user32", "GetSystemMetrics");
int rc = ic.executeCall(new Integer(SM_REMOTESESSION));
return (rc gt; 0);
}
finally {
if (ic != null) ic.destroy();
}
}
public static void main(String ... args) throws Exception {
System.out.println(WindowsUtils.isRemote());
}
}
public static boolean isRemoteDesktopSession() {
System.getenv("sessionname").contains("RDP");
}
Written and compiled by Réal Gagnon ©1998-2012
[ home ]