using System.Runtime.InteropServices;
using SLID = System.Guid;
public class WindowsInfo {
public enum SL_GENUINE_STATE {
SL_GEN_STATE_IS_GENUINE = 0,
SL_GEN_STATE_INVALID_LICENSE = 1,
SL_GEN_STATE_TAMPERED = 2,
[DllImportAttribute("Slwga.dll", EntryPoint = "SLIsGenuineLocal", CharSet = CharSet.None, ExactSpelling = false, SetLastError = false, PreserveSig = true, CallingConvention = CallingConvention.Winapi, BestFitMapping = false, ThrowOnUnmappableChar = false)]
internal static extern uint SLIsGenuineLocal(ref SLID slid, [In, Out] ref SL_GENUINE_STATE genuineState, IntPtr val3);
public static string WindowsReleaseId => Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ReleaseId", "").ToString();
private static bool WindowsIsActive {
bool _IsGenuineWindows = false;
Guid ApplicationID = new Guid("55c92734-d682-4d71-983e-d6ec3f16059f"); //Application ID GUID http://technet.microsoft.com/en-us/library/dd772270.aspx
SLID windowsSlid = (Guid)ApplicationID;
SL_GENUINE_STATE genuineState = SL_GENUINE_STATE.SL_GEN_STATE_LAST;
uint result = SLIsGenuineLocal(ref windowsSlid, ref genuineState, IntPtr.Zero);
if (result == 0) _IsGenuineWindows = (genuineState == SL_GENUINE_STATE.SL_GEN_STATE_IS_GENUINE);
return _IsGenuineWindows;
public static string WindowsActiveState => Environment.OSVersion.Version.Major < 6 ? "不支持的系统" : WindowsIsActive ? "已激活" : "未激活";
public static string WindowsVersion {
using (ManagementObjectSearcher win32OperatingSystem = new ManagementObjectSearcher("select * from Win32_OperatingSystem")) {
foreach (ManagementObject obj in win32OperatingSystem.Get())
return $"{obj["Caption"]} ({obj["OSArchitecture"]})";
评论