poidasmith / winrun4j

WinRun4J Java Application Launcher
http://winrun4j.sourceforge.net
212 stars 63 forks source link

Way to detect WinRun4j #28

Closed anm43 closed 11 years ago

anm43 commented 11 years ago

How can I detect from a running program whether it is run via WinRun4j or not?

poidasmith commented 11 years ago

Best way I can think of for now is the following:

import org.boris.winrun4j.Native;

public class WinRun4JTest
{
    public static boolean isRunningInLauncher() {
        try {
            Native.loadLibrary("kernel32");
            return true;
        } catch(Throwable t) {
            return false;
        }
    }

    public static void main(String[] args) throws Exception {
        System.out.println(isRunningInLauncher());
    }
}
anm43 commented 11 years ago

thank you for the fast answer. It works. I find it kind of "heavy". It would be nice to have an FAQ and this question in my opinion belongs there. I would suggest setting a property like "winrun4j" to "true" that could be later read using System.getProperty()

poidasmith commented 11 years ago

Agreed. You could always set it in your INI file:

vmarg.1=-Dwinrun4j=true