Check for a feature and not a version

The most important thing I learned from a presentation of Andrew Coates on Windows development was

If you use a specific feature of a Windows OS, check for that specific feature and not for the Windows OS version!

 

E.g. You create an awesome application that uses the new Windows 7 taskbar features!

bad BAD: DON’T determine the windows OS version and react on that (enable/disable functionality), but test the API for the feature!
DON’T use code mentioned in this blog post: “Determine Windows Version and Edition with C#” or more complicated here: C# Detect Windows OS Version


good GOOD: Use the API provided from Microsoft for Windows 7 : Windows API Code Pack

Add this namespace

using Microsoft.WindowsAPICodePack.Taskbar;

Verify this property on the class TaskbarManager

TaskbarManager.IsPlatformSupported

 

PS
In this blog post you can found how you use the progress bar of the Windows 7 taskbar

3 comments:

Andrew said...

Being the author of the "more complicated" blog post, I must agree. If you need to determine if a feature is available, don't do it by detecting the OS. The same is true for javascript in web development. Don't browser-detect, feature-detect.

That being said. There are very legitimate reasons for wanting to know your client's OS. Gathering demographic info is probably the most common. For my particular situation, I wanted to know the OS to include that info in my automated error reporting.

Just because a tool isn't for the job at hand, that doesn't mean it's a worthless or "BAD" tool.

Peter Gfader said...

Andrew,

Thank you for your comment.
Agree, I use similar code to get the current running Windows version in my exception logs :-)

I just googled and found your explanation and used that as a refernce...

Thanks for posting your code on your blog, although I didn't test it :-)
I follow ya!

Andrew said...

Sure. Thanks for your comment on my blog. Thanks for the link to my blog. Glad to know I'm visible on Google!

Post a Comment

Latest Posts

Popular Posts