By Chad Upton
When you’re building an application, particularly a desktop (AIR) application, you may need to know which operating system the user is running for various reasons.
Perhaps you’ve got a logging system or an analytics service you need to report to; maybe your application interacts with each operating system differently.
Either way, it’s a good practice to use the constant file paths that are defined in the File class (ex. File.ApplicationDirectory). That way, no matter which operating system the user is running, AIR will map the path to that folder correctly. But, if you’re interacting with files that were put there by another application, it may be necessary to detect the operating system so you can build your own file paths.
To get the operating system, you’ll read the value from: Capabilities.os
You should get a value such as “Windows XP”, “MacOS” or “Linux”, which you’ll find reference to in the docs. However, the docs do not indicate what you’ll get for Windows Vista and Windows 7. As you can probably imagine, you will get “Windows Vista” and “Windows 7″, which is true. But beware, if you launch your application from Flash Builder on Windows 7, the value will actually be simply, “Windows”. It does return the correct value on Windows XP and Vista.
So, here are the values you should get for the more recent versions of Windows:
- XP: “Windows XP”
- Vista: “Windows Vista”
- 7: “Windows 7″
- 7 Debug mode (launched from Flash Builder): “Windows”
For more information, please consider our professional onsite and online training services.




