【问题标题】:Find what windows version is on a specified drive查找指定驱动器上的 Windows 版本
【发布时间】:2016-12-29 17:44:50
【问题描述】:

我想查找驱动器 D 上的操作系统版本(例如:Window 7 Pro):无需深入了解D:\Windows\System32\license.rtf

System.Management 命名空间中是否有一个类可以让我在指定的本地驱动器号上查找操作系统版本?

【问题讨论】:

  • 如果机器的操作系统没有在有问题的驱动器上运行,那么没有简单的方法。 Windows 只知道自己。您必须寻找许可证文件等指标。用例是什么?为什么您会在驱动器上安装操作系统但不运行它?
  • 您可以将该驱动器的本地计算机注册表配置单元加载到 C# 中,然后检查注册表中的标记。
  • 我在 license.rtf 文件中看不到任何有用的信息?您可以在 windows 文件夹下获取任何二进制文件并获取其版本(例如 \Windows\explorer.exe),然后使用版本映射 -> en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions
  • @john Registry.LocalMachine.OpenSubKey(path);工作,但如果我添加 C:
  • 由于某种原因,我不会编辑最后一篇文章。 @john Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows") 有效,可用于查找“ProductName”键。如何更改注册表路径的根目录?

标签: c# windowsversion


【解决方案1】:
    //This will help you detect the version of the OS for NT based system, if ntoskrnl.exe doesnt exist its ME/95/98
    var DriveLetter = "D"; //D drive.
    var pathTontoskrnl = string.Format("{0}:\\{1}", DriveLetter, "\\Windows\System32\ntoskrnl.exe");
    if (!File.Exists(pathTontoskrnl))
    {
        Console.WriteLine("Windows ME/95/98");  
    }
    var versionInfo = FileVersionInfo.GetVersionInfo(pathTontoskrnl);
    string version = versionInfo.ProductVersion; 
    if ( version.StartsWith("5.1") )
    {
        Console.WriteLine("XP");
    }
    //4.x: NT 4.x
    //5.0: Win2k
    //5.1: WinXP
    //5.2: Win2003 or XP-x64
    //6.0: WinVista
    //6.1: Win7
    //6.2; Win8
    //6.3: Win8.1
    //6.4: Win10 ??? (not sure)

【讨论】:

  • 这确实有效,但遗憾的是版本号不能用于确定操作系统版本之间的差异,例如 Windows 7 pro VS Windows 7 Home Premium。是否有其他方法可以识别不同的版本?
  • 如果 Windows 安装到不是“*:/Windows/”的目录,这也会失败
  • 正确,这就是pathTontoskrnl是一个变量的原因,可以根据你想要传递windows的安装目录来构造。
猜你喜欢
  • 1970-01-01
  • 2010-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-09
相关资源
最近更新 更多