C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Operating System »

Get the OS version


Posted Date: 28 Aug 2009    Resource Type: Code Snippets    Category: Operating System
Author: Shunmuganathan MMember Level: Diamond    
Rating: 1 out of 5Points: 10



We can get the version of the OS by using the following code

Namespace Part

using System;
using System.Runtime.InteropServices;


Code part for get the version of the OS

public class OSVersion {
public static void Main() {
MyAPI.OSVERSIONINFO MyAPIinfo = new MyAPI.OSVERSIONINFO();
MyAPIinfo.dwOSVersionInfoSize = Marshal.SizeOf(MyAPIinfo);
bool MyBool = MyAPI.GetVersionEx(ref MyAPIinfo);
if (MyBool == false) {
Console.WriteLine("GetVersion failed");
}
Console.WriteLine("{0}.{1}.{2}",
MyAPIinfo.dwMajorVersion,
MyAPIinfo.dwMinorVersion,
MyAPIinfo.dwBuildNumber);
}
}


Code for API to get the details

public class MyAPI {

[DllImport("kernel32.dll")]
public static extern
bool GetVersionEx(ref OSVERSIONINFO lpVersionInfo);

[StructLayout(LayoutKind.Sequential)]
public struct OSVERSIONINFO {
public System.Int32 dwOSVersionInfoSize;
public System.Int32 dwMajorVersion;
public System.Int32 dwMinorVersion;
public System.Int32 dwBuildNumber;
public System.Int32 dwPlatformId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public String szCSDVersion;

}

}



1. Write the MyAPI class for getting the OS details
2. kernel32.dll is used to achive this target.
3. By using the we can get the Majorversion ,Miniorversion and buildnumber


By
Nathan



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Get the OS version  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Open or close the CD drive
Previous Resource: user32.dll message box
Return to Discussion Resource Index
Post New Resource
Category: Operating System


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use