This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
We have a java app that is installed on different Windows platforms, and we've been using System.getProperty("os.name") for a long time to determine the OS the app is running under. We use this info to track how many installations we have under each Windows platform. Also, our app is packaged as an executable via InstallAnywhere.
With the newer versions of Windows (Vista, Windows 7, Windows Server 2008), we're usually getting the correct OS name back... so if it's installed under Windows 7 we're getting "Windows 7" back. However, under these new OSes, a user can set the "compatibility mode" to an older OS such as Windows XP. We're finding that the "os.name" property is coming back as whatever OS is selected for this compatibility mode. For example, if the application is installed to Windows 7, but the executable's compatibility mode is set to Windows XP, then the call to System.getProperty("os.name") is returning "Windows XP".
Does anyone know if there's a way to get the real OS? We're tossing around the idea of making an external system call or running another executable that writes the real OS name to a temporary file we can then read... but that's not foolproof either since someone can set the compatibility mode for that executable as well.
I don't think there is a pure-Java solution to this, since the problem is very Windows-specific. Creating a native executable that does Windows system calls and somehow finds out what the real operating system is sounds like something you could do. But you're really trying to work against the intention of Windows compatibility mode - the whole idea is ofcourse to make the app think that it works on an older Windows version.
Ultimately, the question is how well you trust your users. Do you really have users that deliberately want to trick you by making the software run in compatibility mode (what motives would they have to make you think they're running Windows XP?). Are there really that many users running your software in compatibility mode (what would be their reason to make it run in compatibility mode?) so that it seriously affects your statistics?