---
title: "How to Detect the Windows version in .NET?"  
description: "How to Detect the Windows version in .NET?"  
author: "Utpal Vishwas"  
published: 2023-07-13  
updated: 2023-07-14  
canonical: https://www.mindstick.com/forum/159068/how-to-detect-the-windows-version-in-dot-net  
category: ".net"  
tags: [".net", "asp.net", "windows"]  
reading_time: 2 minutes  

---

# How to Detect the Windows version in .NET?

How to [Detect](https://www.mindstick.com/forum/1906/detect-when-cd-drive-was-closed) the [Windows](https://www.mindstick.com/articles/311752/how-to-install-and-use-the-google-wifi-software-on-a-windows-or-mac-computer) [version](https://www.mindstick.com/articles/12845/things-to-remember-while-migrating-odoo-to-a-better-version) in .NET?

## Replies

### Reply by Aryan Kumar

Sure, here is how to detect Windows version in .NET:

C#

```plaintext
using System;

namespace DetectWindowsVersion
{
    class Program
    {
        static void Main(string[] args)
        {
            // Get the Windows version.
            var windowsVersion = Environment.OSVersion;

            // Print the Windows version.
            Console.WriteLine("Windows version: {0}", windowsVersion.VersionString);
        }
    }
}
```

This code will first get the Windows version from the `Environment` object. The `Environment` object provides information about the environment that the code is running in.

Next, the code will print the Windows version to the console. The `VersionString` property of the `OSVersion` class returns a string that represents the Windows version.

Here is an example of the output of this code:

```plaintext
Windows version: 10.0.19043.1237
```

This output shows that the computer is running Windows 10, version 20H2.

Here is a table summarizing the key properties of the `OSVersion` class:

| Property | Description |
| --- | --- |
| Version | The Windows version number. |
| MajorVersion | The major version number of Windows. |
| MinorVersion | The minor version number of Windows. |
| BuildNumber | The build number of Windows. |
| Revision | The revision number of Windows. |
| VersionString | A string that represents the Windows version. |


---

Original Source: https://www.mindstick.com/forum/159068/how-to-detect-the-windows-version-in-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
