(view source code of winvercl.cs as plain text)
using System;
using Microsoft.Win32;
namespace RobvanderWoude
{
internal class WinVerCL
{
static readonly string progver = "1.00";
static int Main( string[] args )
{
// Old NT versioning system, as in VER command
string os = Environment.OSVersion.VersionString;
Console.WriteLine( );
Console.WriteLine( os );
Console.WriteLine( );
// Friendly version name, as in WinVer command
string displayversion, osbuild, productname, ubr;
try
{
// try forcing accessing 64-bit registry first, otherwise the program may choose 32-bit even on 64-bit systems
using ( RegistryKey hklm64 = RegistryKey.OpenBaseKey( RegistryHive.LocalMachine, RegistryView.Registry64 ) )
{
using ( RegistryKey currentversion = hklm64.OpenSubKey( "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion" ) )
{
productname = currentversion.GetValue( "Productname", "Unknown" ).ToString( );
displayversion = currentversion.GetValue( "DisplayVersion", "" ).ToString( );
osbuild = currentversion.GetValue( "CurrentBuildNumber", "Unknown" ).ToString( );
ubr = currentversion.GetValue( "UBR", "" ).ToString( );
}
}
}
catch
{
using ( RegistryKey hklm32 = RegistryKey.OpenBaseKey( RegistryHive.LocalMachine, RegistryView.Registry32 ) )
{
using ( RegistryKey currentversion = hklm32.OpenSubKey( "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion" ) )
{
productname = currentversion.GetValue( "Productname", "Unknown" ).ToString( );
displayversion = currentversion.GetValue( "DisplayVersion", "" ).ToString( );
osbuild = currentversion.GetValue( "CurrentBuildNumber", "Unknown" ).ToString( );
ubr = currentversion.GetValue( "UBR", "" ).ToString( );
}
}
}
if ( !string.IsNullOrWhiteSpace( ubr ) )
{
osbuild = String.Format( "{0}.{1}", osbuild, ubr );
}
Console.WriteLine( "{0} {1} (OS Build {2})", productname, displayversion, osbuild );
Console.WriteLine( );
return 0;
}
}
}
page last modified: 2024-04-16; loaded in 0.0065 seconds