The release number of this article has been CHS304721
For Microsoft Visual Basic .NET versions of this article, see
304722.
For Microsoft Visual C .NET versions of this article, see
307393.
Summary to get operating system information
The OSVersion property does not include a member of the service pack information. If you want to determine what Service Pack installed, you must call it.
GetversionEx API function. Usually, it is best to avoid this approach - .NET framework provides access to the base API set, more consistent than calling a single API function (and more easily). When you need to call the API function directly, you can implement it through the .NET framework. The code in this article provides a method called GetServicePack, which will return to the service pack level.
MORE INFORMATION The following steps demonstrate how to generate a GetServicePack method. Note that the OsVersionInfo structure contains a string of fixed length:
Szcsdversion. Since the fixed length string is no longer supported, it is necessary to provide the seal processing information for this member. This is achieved by using properties in front of the member name (represented by []).
Open a new C # .NET console application. Open the Class1.cs code window and then delete all code. Paste the following code to Class1.cs. Using system;
Using system.reflection;
Using system.Runtime.InteropServices;
Class class1
{
Static void main (string [] args)
{
Console.writeLine (GetServicePack ());
}
[Structlayout (layoutkind.sequential)]
Public struct OsversionInfo
{
Public int dwosveionsInfosize;
Public Int dwmajorversion;
Public Int dwminorversion;
Public int dwbuildnumber;
Public int dwplatformID;
[Marshalas (UnmanagedType.Byvaltstr, SIZECONST = 128)]]]
Public String Szcsdversion;
}
[DLLIMPORT ("kernel32.dll")] public static extern short getversionex (Ref OsversionInfo O);
Static Public String GetServicePack ()
{
OsversionInfo OS = New OsversionInfo ();
Os.dwosveionsInfosize = Marshal.sizeOf (Typeof (OsversionInfo);
GetVersionex (Ref OS);
IF (os.szcsdversion == "")
Return "No Service Pack Installed";
Else
Return Os.szcsdversion;
}
} Press CTRL F5 combination to generate and run the project. Note that Service Pack is displayed in the console window.
The information in this article applies to:
Microsoft Visual C # .NET (2002)