System information

  • Thread starter Thread starter Markus Wildgruber
  • Start date Start date
M

Markus Wildgruber

Hi!

How can I get information about the system my application is running on? I
found the System.Environment class that provides me with some of the desired
information but some of them not in the form I want.
For example, you can get the OS-version but when using ToString() to do the
user output, it returns 'Microsoft Windows NT 5.1.2600.0' when running on
Windows XP Professional.
Is there a way to get a user-understandable string like 'Windows XP
Professional' or 'Windows 2000 Server'?

Are there any other namespaces/classes that can provide me with system
information like the OS name (Windows XP) and version?
Do I have to use PInvoke?

TIA,

Markus
 
Hi Markus,

Thank you for posting in the community! My name is Jeffrey, and I will be
assisting you on this issue.

Based on my understanding, you want to collect some useful information of
your operating system, such as OS version.

=====================================================
In .Net, just as you find, the simplest way of getting the system version
information is using System.Environment.OSVersion property.

Internally, Environment.OSVersion.ToString() will default return the full
code information of the OS, for XP, it is "Microsoft Windows NT 5.1.2600.0".
This system information string is the Windows' system information define
rule.
Similarly, the "Microsoft Windows NT" property indicates one of the
following operating systems:
Windows NT 3.51
Windows NT 4.0
Windows 2000
Windows XP

For 5.1.2600.0, '5' is the major component of the version number(It means
Windows XP system). '1' is the minor component of the version number for
this instance. '2600' is the build component of the version number for this
instance. While '0' is the revision component of the version number for
this instance.

You can use Environment.OSVersion.Platform to return a PlatformID
enumeration which get Win32NT,
and you can use Environment.OSVersion.Version to return a Version object,
which has 4 properties: Build, Major, Minor, Revision will get "5.1.2600.0"
part.

For more detailed information and sample, please refer to the article
below(This is C# version):
http://support.microsoft.com/default.aspx?scid=kb;en-us;304283

Actually, "system information" is a wide concept, there is not a common way
to retrieve all the "system information" of the entire system. You also can
refer to System.Windows.Forms.SystemInformation class to get information
such as Windows display element sizes, operating system settings, network
availability, and the capabilities of hardware installed on the system.
Please refer it in MSDN document.

=================================================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Have a nice experience on using Microsoft Newsgroup!!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Jeffrey,

thanks a lot for your reply. It solved my issue for the moment.

I found the knowledge base article too, but I was wondering whether there
was an easier way to get that information. If you have to analyze the
OSVersion information, you end up using a lot of 'if'-statements (that have
to be kept up-to-date when new windows versions are released). It would be
very convinient if the .NET framework (or better the OS APIs itself) had
support for that out of the box.

Thanks again for your reply,

Markus

"Jeffrey Tan[MSFT]" said:
Hi Markus,

Thank you for posting in the community! My name is Jeffrey, and I will be
assisting you on this issue.

Based on my understanding, you want to collect some useful information of
your operating system, such as OS version.

=====================================================
In .Net, just as you find, the simplest way of getting the system version
information is using System.Environment.OSVersion property.

Internally, Environment.OSVersion.ToString() will default return the full
code information of the OS, for XP, it is "Microsoft Windows NT 5.1.2600.0".
This system information string is the Windows' system information define
rule.
Similarly, the "Microsoft Windows NT" property indicates one of the
following operating systems:
Windows NT 3.51
Windows NT 4.0
Windows 2000
Windows XP

For 5.1.2600.0, '5' is the major component of the version number(It means
Windows XP system). '1' is the minor component of the version number for
this instance. '2600' is the build component of the version number for this
instance. While '0' is the revision component of the version number for
this instance.

You can use Environment.OSVersion.Platform to return a PlatformID
enumeration which get Win32NT,
and you can use Environment.OSVersion.Version to return a Version object,
which has 4 properties: Build, Major, Minor, Revision will get "5.1.2600.0"
part.

For more detailed information and sample, please refer to the article
below(This is C# version):
http://support.microsoft.com/default.aspx?scid=kb;en-us;304283

Actually, "system information" is a wide concept, there is not a common way
to retrieve all the "system information" of the entire system. You also can
refer to System.Windows.Forms.SystemInformation class to get information
such as Windows display element sizes, operating system settings, network
availability, and the capabilities of hardware installed on the system.
Please refer it in MSDN document.

=================================================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Have a nice experience on using Microsoft Newsgroup!!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Markus,

Does my reply make sense to you?
If you still have any concern, please feel free to tell me, I will work
with you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Jeffrey!

Yes, your answer does make sense to me. It solves the problem but as written
in my first response it would be very convenient if the OS-API itsef had
support for getting the user friendly name of the windows version.

Thanks again,

Markus
 
Hi Markus,

Thanks you very much for your feedback. I am glad my reply makes sense to
you.

=========================================================
For your further concern, you will see in document that
System.Environment.OSVersion property returns OperatingSystem object that
contains the current platform identifier and version number.

Based on my experience, I think System.Environment.OSVersion encapsulate
the Win32 API function GetVersionEx(You can view it in MSDN), which is the
standard function used in Win32 platform to retrieve the version
information of the operating system that is currently running.

In GetVersionEx document will see that it gets an OSVERSIONINFO structure
which also contains the Major version number, Minor version number, Build
number etc.

These numbers give a uniform version information modal, which is easily to
extend.(If a new service pack or others is released, it only need to change
one related number)

Anyway, it is defined as this by convention, I think the correct way to use
it is following the remarks and information in MSDN document.

I really hope my reply makes sense to you.

=========================================================
If you still have any further concern, please feel free to tell me, I will
work with you.
Have a nice day!!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top