首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >识别Windows 10企业LTSB

识别Windows 10企业LTSB
EN

Stack Overflow用户
提问于 2016-01-13 00:55:05
回答 1查看 467关注 0票数 2

应用程序如何检测它是否运行在Windows 10企业LTSB (长期服务分支)上?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-13 01:44:37

GetProductInfo API函数返回该信息。

代码语言:javascript
运行
复制
using System;
using System.Runtime.InteropServices;
using System.Text;

namespace ConsoleApplication4
{
  public class Program
  {
    [DllImport("kernel32.dll", SetLastError = true)]
    internal static extern Boolean GetProductInfo(
      Int32 dwOSMajorVersion,
      Int32 dwOSMinorVersion,
      Int32 dwSpMajorVersion,
      Int32 dwSpMinorVersion,
      out Int32 pdwReturnedProductType);

    [DllImport("Kernel32.dll", CharSet = CharSet.Auto, EntryPoint = "FormatMessage", SetLastError = true)]
    internal static extern Int32 FormatMessage(
      Int32 flags,
      IntPtr source,
      Int32 messageId,
      Int32 languageId,
      StringBuilder buffer,
      Int32 size,
      IntPtr arguments);

    public static void Main(String[] args)
    {
      /* Other product codes can be found on the help page for
         the GetProductInfo API function:
         https://msdn.microsoft.com/en-us/library/windows/desktop/ms724358%28v=vs.85%29.aspx */

      const Int32 PRODUCT_ENTERPRISE_S = 0x7D;

      var productId = GetProductIdNumber();

      Console.Write("Product: ");
      Console.WriteLine(
        (productId == PRODUCT_ENTERPRISE_S)
        ? "Windows 10 LTSB"
        : "Product Number " + productId.ToString("X"));
    }

    private static Int32 GetProductIdNumber()
    {
      Int32 productId;

      if (GetProductInfo(
          Environment.OSVersion.Version.Major,
          Environment.OSVersion.Version.Minor,
          0,
          0,
          out productId))
        return productId;
      else
        throw new Exception(GetSystemErrorMessage(Marshal.GetLastWin32Error()));
    }

    private static String GetSystemErrorMessage(Int32 win32ErrorCode)
    {
      const Int32 formatMessageFromSystem = 0x00001000;
      const Int32 defaultLanguageID = 0;

      var buffer = new StringBuilder(256);
      var numberOfCharactersInBuffer = FormatMessage(formatMessageFromSystem, IntPtr.Zero, win32ErrorCode, defaultLanguageID, buffer, buffer.Capacity, IntPtr.Zero);

      if (numberOfCharactersInBuffer > 0)
        return buffer.ToString().Trim();
      else
        return String.Concat("Error ", win32ErrorCode, " occurred.  No error description is available.");
    }
  }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34756625

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档