Sathya R
Sathya R

Reputation: 413

Determine if given OS name is server-based or desktop-based

My java based application is installed in a number of Users' computer. During the first run, it automatically sends the user's OS name to my server and is stored in database. I used System.getProperty("os.name"); to get the user's Operating System name in that application. Is that possible to determine if that is a Server based Computer(Windows Server 2012 Standard) or Desktop Computer(Ubuntu, Windows 7)?

Is there any possible way to determine between Server and Desktop Computer with Java?

Upvotes: 1

Views: 253

Answers (2)

Stephen C
Stephen C

Reputation: 718826

Is there any possible way to determine between Server and Desktop Computer with Java?

(Assuming that you can get the value of the "os.name" property for the relevant machine.)

The answer is there isn't a reliable way.

For a start, there is no hard distinction between a server and desktop computer. I can take a headless server installation of Linux and turn it into a desktop Linux simply by installing a few packages. The OS doesn't change, the distribution doesn't change, and the string in the "os.name" property won't change.

The best you can do is to figure out common patterns for "os.name" strings on various common Java + OS platforms. But that will be fragile, at best.

Upvotes: 0

user149341
user149341

Reputation:

I use System.getProperty("os.name"); in a Java based web application to get the user's Operating System name.

That gets you the operating system name of the server that's running the web application, not the user's computer.

You can try to extract operating system information from the browser's User-Agent header, but this is inherently an error-prone process. Moreover, Microsoft Windows is the only operating system that has a clear server/desktop distinction of the sort you're looking for; Linux and macOS do not have any such distinction.

Upvotes: 3

Related Questions