Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

GetVersion (kernel32)
 
.
Summary

C# Signature:

[DllImport("kernel32.dll")]
static extern uint GetVersion();

User-Defined Types:

None.

Notes:

Retrieves the version number of the current operating system

Tips & Tricks:

Please add some!

Sample Code:

using System;

using System.Text;

using System.Runtime.InteropServices;

namespace testt

{

    class Program
    {
    static void Main(string[] args)
    {
        StringBuilder str = new StringBuilder(100);
        uint dwWersion = WinAPI.GetVersion();

        str.Append(WinAPI.LoByte((ushort)WinAPI.LoWord(dwWersion)));
        str.Append(".");
        str.Append(WinAPI.HiByte((ushort)WinAPI.LoWord(dwWersion)));
        if (dwWersion < 0x80000000)
        {
        str.Append("." + WinAPI.HiWord(dwWersion).ToString());
        }
        Console.WriteLine("OS Version is " + str.ToString());
    }
    }

    static class WinAPI
    {
    public static uint LoWord(uint dwValue)
    {
        return dwValue & 0xFFFF;
    }

    public static uint HiWord(uint dwValue)
    {
        return (dwValue >> 16) & 0xFFFF;
    }

    public static ushort LoByte(ushort wValue)
    {
        return (ushort)(wValue & 0xFF);
    }

    public static ushort HiByte(ushort wValue)
    {
        return (ushort)((wValue >> 8) & 0xFF);
    }

    [DllImport("kernel32.dll")]
    public static extern uint GetVersion();
    }

}

Alternative Managed API:

GetVersionEx(), Operating System Version(), VerifyVersionInfo()

Documentation
<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms724439(v=vs.85).aspx">GetVersion</href>@msdn on MSDN

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions