1

I want to find what OS version (e.g.: Window 7 Pro) is on drive D: without digging through D:\Windows\System32\license.rtf

Is there a class within System.Management namespace that will let me find OS Versions on a specified local drive letter?

Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164
Simon
  • 11
  • 1
  • 4
    If the machine's OS is not running on the drive in question then there's no simple way. Windows is only aware of itself. You'll have to look for indicators like the license file. What's the use case? Why would you have an OS installed on a drive but not be running it? – Dan Wilson Dec 29 '16 at 17:48
  • 2
    You could load the local machine registry hive for that drive into C# and then check markers in the registry. – ProgrammingLlama Dec 29 '16 at 17:51
  • I can't see any useful info in license.rtf file ? You can get any binary under windows folder and get its version (e.g `\Windows\explorer.exe`) and then use the versions mapping - > https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions – npocmaka Dec 29 '16 at 18:02
  • @john Registry.LocalMachine.OpenSubKey(path); works but not if i add C: – Simon Dec 30 '16 at 18:16
  • For some reason it won’t me edit the last post. @john Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows") works and can be used to find the “ProductName” key. How could I change the root of the registry path? – Simon Dec 30 '16 at 18:24

1 Answers1

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)
Sanjeevakumar Hiremath
  • 10,985
  • 3
  • 41
  • 46
  • This does work, but unfortunately the version numbers can not be used to determine the difference between OS editions, such as Windows 7 pro VS Windows 7 Home Premium. Is there another way to do this that could identify the different editions? – Simon Dec 30 '16 at 15:40
  • This will also fail where windows is installed to a directory that is not "*:/Windows/" – Kraang Prime Dec 30 '16 at 21:07
  • Correct, thats the reason pathTontoskrnl is a variable, that can be constructed based on however you want to pass the installation directory of windows. – Sanjeevakumar Hiremath Jan 03 '17 at 05:28