Forum Discussion

Capricornus's avatar
Capricornus
Contributor
2 years ago
Solved

How to get Windows Version and dotnet version info (OSInfo)

Hello everyone,

I want to log the current Windows version and the latest .NET runtime that is installed in every test in a "version.txt" file

The OSInfo.Version only shows "10.0 Build 19045" and OSInfo.ServicePackVersion is empty. What I want is something like "Windows 10 22H2".

 

Also Sys.OSInfo.NetCoreVersion(Sys.OSInfo.NetCoreCount -1) shows v4.0.30319 instead of 7.0.0

 

Maybe somebody can help me 🙂

 

Best regards

 

  • Windows naming convention has changed, see https://en.wikipedia.org/wiki/Windows_10_version_history. You will have to write a function to convert the build number i.e. 19044 to "21H2", which then refers to the cumulative update, November 2021 Update.

     

    You can get this information also, using PowerShell script, which you can then output to a file

2 Replies

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Windows naming convention has changed, see https://en.wikipedia.org/wiki/Windows_10_version_history. You will have to write a function to convert the build number i.e. 19044 to "21H2", which then refers to the cumulative update, November 2021 Update.

     

    You can get this information also, using PowerShell script, which you can then output to a file

  • For extracting the .NET version, I found the following solution (if somebody is interested):

     

     

    function dotNetVersion() {
      let version
      let shell
      let position
    
      // call dotnet --info in Windows shell
      shell =  WshShell.Exec("dotnet --info");
      shell.StdIn.Close(); 
    
      // Analyze the output to extract the version number
      // section in question is:
      // Host:
      //   Version:    x.y.z
      version = shell.StdOut.ReadAll();
      position = aqString.Find(version, "Host:");
    
      version = aqString.SubString(version, position, 100);
      position = aqString.Find(version, "Version:");
    
      version = aqString.SubString(version, position, 100).split("\r\n")[0];
      version = aqString.Trim(aqString.SubString(version,8,aqString.GetLength(version)-1));
      
      Log.Message(`.NET version: ${version}`);
    }