[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework

How to find OS version

mohandasg

10/27/2008 5:40:00 PM

'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
3 Answers

Jeroen Mostert

10/27/2008 6:06:00 PM

0

mohandasg@gmail.com wrote:
> '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...)

--
J.

Cowboy

10/28/2008 1:14:00 PM

0

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/Greg...

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

********************************************
| Think outside the box! |
********************************************
<mohandasg@gmail.com> wrote in message
news:4118ab0b-10ab-4950-b1a9-6fd32d45b6c5@v72g2000hsv.googlegroups.com...
> '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

Jeroen Mostert

10/28/2008 6:50:00 PM

0

Cowboy (Gregory A. Beamer) wrote:
> 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. :-)

--
J.