Wednesday, 1 August 2012

.Net Tips , C# Tips : Get Operating System name and version details of server with C# Examples and VB.Net Examples

You can get Operation System (OS) name and major version and minor version details,service pack and build details of server using  "System.Environment" class.
We can use OSVersion property of Environment Class which will return "OperatingSystem" class.

Here is example for this.
In this example we display server name ,it's version details , service pack and build details.

C# Examples :
        Response.Write("<b>OS Platform :</b> " + Environment.OSVersion.Platform);
        Response.Write("<br/><br/>");
        Response.Write("<b>OS Major Version :</b> " + Environment.OSVersion.Version.Major);
        Response.Write("<br/><br/>");
        Response.Write("<b>OS Minor Version :</b> " + Environment.OSVersion.Version.Minor);
        Response.Write("<br/><br/>");
        Response.Write("<b>OS Build number :</b> " + Environment.OSVersion.Version.Build);
        Response.Write("<br/><br/>");
        Response.Write("<b>OS Service Pack :</b> " + Environment.OSVersion.ServicePack);
        Response.Write("<br/><br/>");
        Response.Write("<b>OS Version String :</b> " + Environment.OSVersion.VersionString);

VB.net Example :
        Response.Write("<b>OS Platform :</b> " & Environment.OSVersion.Platform.ToString())
        Response.Write("<br/><br/>")
        Response.Write("<b>OS Major Version :</b> " & Environment.OSVersion.Version.Major)
        Response.Write("<br/><br/>")
        Response.Write("<b>OS Minor Version :</b> " & Environment.OSVersion.Version.Minor)
        Response.Write("<br/><br/>")
        Response.Write("<b>OS Build number :</b> " & Environment.OSVersion.Version.Build)
        Response.Write("<br/><br/>")
        Response.Write("<b>OS Service Pack :</b> " & Environment.OSVersion.ServicePack)
        Response.Write("<br/><br/>")
        Response.Write("<b>OS Version String :</b> " & Environment.OSVersion.VersionString)
        Response.Write("<br/><br/>")

Output :

This type of C# Tips is very useful in day to day programming life.

Note : Give Us your valuable feedback in comments. Give your suggestions in this article so we can update our articles accordingly that.



 

No comments:

Post a Comment