Reputation: 3459
I wrote a Java application because the official application is only available for Windows. Because I want to ensure that I don't get into trouble I want to prohibit that it runs on Windows.
What can I check to know if the application runs on Windows and therefore immediately quit the application?
Other advises are welcome, too.
Upvotes: 0
Views: 62
Reputation: 20520
I'd recommend using the Apache Commons Lang library for this. It has a SystemUtils.IS_OS_WINDOWS
, whose purpose is to do this for you. Check this boolean
, and if it's set, then use System.exit(1)
(or some appropriate value).
It'll save you worrying about whether you're correctly interpreting the result of the System.getProperty()
call.
By the way, you might consider getting your application to launch the official application instead of exiting. You could do it either way.
Upvotes: 2
Reputation: 5147
You can use:
System.getProperty("os.name")
If its windows use
System.exit(-1)
Upvotes: 2