Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for winvercl.cs

(view source code of winvercl.cs as plain text)

  1. using System;
  2. using Microsoft.Win32;
  3.  
  4.  
  5. namespace RobvanderWoude
  6. {
  7. 	internal class WinVerCL
  8. 	{
  9. 		static readonly string progver = "1.00";
  10.  
  11.  
  12. 		static int Main( string[] args )
  13. 		{
  14. 			// Old NT versioning system, as in VER command
  15. 			string os = Environment.OSVersion.VersionString;
  16. 			Console.WriteLine( );
  17. 			Console.WriteLine( os );
  18. 			Console.WriteLine( );
  19.  
  20. 			// Friendly version name, as in WinVer command
  21. 			string displayversion, osbuild, productname, ubr;
  22. 			try
  23. 			{
  24. 				// try forcing accessing 64-bit registry first, otherwise the program may choose 32-bit even on 64-bit systems
  25. 				using ( RegistryKey hklm64 = RegistryKey.OpenBaseKey( RegistryHive.LocalMachine, RegistryView.Registry64 ) )
  26. 				{
  27. 					using ( RegistryKey currentversion = hklm64.OpenSubKey( "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion" ) )
  28. 					{
  29. 						productname = currentversion.GetValue( "Productname", "Unknown" ).ToString( );
  30. 						displayversion = currentversion.GetValue( "DisplayVersion", "" ).ToString( );
  31. 						osbuild = currentversion.GetValue( "CurrentBuildNumber", "Unknown" ).ToString( );
  32. 						ubr = currentversion.GetValue( "UBR", "" ).ToString( );
  33. 					}
  34. 				}
  35. 			}
  36. 			catch
  37. 			{
  38. 				using ( RegistryKey hklm32 = RegistryKey.OpenBaseKey( RegistryHive.LocalMachine, RegistryView.Registry32 ) )
  39. 				{
  40. 					using ( RegistryKey currentversion = hklm32.OpenSubKey( "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion" ) )
  41. 					{
  42. 						productname = currentversion.GetValue( "Productname", "Unknown" ).ToString( );
  43. 						displayversion = currentversion.GetValue( "DisplayVersion", "" ).ToString( );
  44. 						osbuild = currentversion.GetValue( "CurrentBuildNumber", "Unknown" ).ToString( );
  45. 						ubr = currentversion.GetValue( "UBR", "" ).ToString( );
  46. 					}
  47. 				}
  48. 			}
  49. 			if ( !string.IsNullOrWhiteSpace( ubr ) )
  50. 			{
  51. 				osbuild = String.Format( "{0}.{1}", osbuild, ubr );
  52. 			}
  53. 			Console.WriteLine( "{0} {1} (OS Build {2})", productname, displayversion, osbuild );
  54. 			Console.WriteLine( );
  55.  
  56. 			return 0;
  57. 		}
  58. 	}
  59. }
  60.  

page last modified: 2024-04-16; loaded in 0.0065 seconds