keiki
keiki

Reputation: 3459

How can I prohibit my Java application runs on Windows?

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

Answers (2)

chiastic-security
chiastic-security

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

prashant thakre
prashant thakre

Reputation: 5147

You can use:

System.getProperty("os.name")

If its windows use

System.exit(-1)

Upvotes: 2

Related Questions