How to find OS version

M

mohandasg

'Environment.OSVersion' can be used to find OS version. However how to
differentiate between windows XP (64 bit) and a windows 2K3 ? both
shows major version 5 and minor version 2 .
Also how to differentiate between Vista and windows 2K8?

Thanks
-mhnds
 
J

Jeroen Mostert

'Environment.OSVersion' can be used to find OS version. However how to
differentiate between windows XP (64 bit) and a windows 2K3 ? both
shows major version 5 and minor version 2 .
Also how to differentiate between Vista and windows 2K8?
You can't do this using Environment. You can do it by P/Invoke to
GetVersionEx(): wProductType will be VER_NT_WORKSTATION for XP and Vista and
VER_NT_SERVER for the server editions. Google around, there are a few samples.

Ask yourself whether you really need to do this -- the reason the version
numbers are identical is that the kernels are identical, so the OSes are so
much alike that it should make no difference for most applications. An
installer might need to know this, but installers typically aren't written
as .NET applications (for one thing, you have to make sure .NET is installed
before you can use the installer, which is a bit silly...)
 
C

Cowboy \(Gregory A. Beamer\)

Jeroen has explained why the versions are the same, but I can see some
reasons you might want to know the exact OS, as there are things you might
take advantage of on a server and not a workstation (and vice versa). The
native calls Jeroen has are a good method. If you know you will have proper
access, there are also keys in the registry you can query. The keys are
under:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion

There are quite a few useful keys in here, although you will have to figure
out how to best use them. I am not sure wheter the 32 bit, 64 bit question
is easily answered here, but you can definitely get server versus
workstation.


--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
 
J

Jeroen Mostert

Cowboy said:
If you know you will have proper access, there are also keys in the
registry you can query. The keys are under:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion

There are quite a few useful keys in here, although you will have to
figure out how to best use them. I am not sure wheter the 32 bit, 64 bit
question is easily answered here, but you can definitely get server
versus workstation.
Be kind to Microsoft and your customers and don't have your programs poking
around in registry keys unless they're explicitly documented (which is
relatively rare). The next version of Windows will either have to bend over
backwards to make sure your successful application still works as expected
even though the keys have changed, or else it will do nothing for your
poorly selling application which will break and sell even more poorly as a
result. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top