(view source code of getsysteminformation.cs as plain text)
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace RobvanderWoude{internal class GetSystemInformation
{static string progver = "1.02";
static int Main( string[] args )
{int columnwidth = 0;
SortedList<string, object> sysinfolist = new SortedList<string, object>( );
Type sysinfotype = typeof( SystemInformation );
PropertyInfo[] propertyinfo = sysinfotype.GetProperties( );
for ( int i = 0; i < propertyinfo.Length; i++ )
{string name = propertyinfo[i].Name;
// populate list with property names and valuessysinfolist[name] = propertyinfo[i].GetValue( sysinfotype, null );
// calculate required column widthcolumnwidth = Math.Max( columnwidth, name.Length );
}switch ( args.Length )
{case 0:
// show entire listforeach ( string key in sysinfolist.Keys )
{Console.WriteLine( "{0,-" + columnwidth + "} {1}", key, sysinfolist[key] );
}return 0;
case 1:
if ( args[0].Contains( "?" ) )
{return ShowHelp( );
} // test exact match, no wildcardsforeach ( string key in sysinfolist.Keys )
{if ( key.ToUpper( ) == args[0].ToUpper( ) ) // make the search case insensitive
{ // show matching property and its valueConsole.WriteLine( "{0}: {1}", key, sysinfolist[key] );
string testvalue = string.Format( "{0}", sysinfolist[key] );
int rc;
// return code equals numeric value, if possibleif ( int.TryParse( testvalue, out rc ) )
{return rc;
}return 0;
} } // test wildcard matchesif ( args[0].Contains( "*" ) )
{bool matchfound = false;
// exclude partial matchesstring pattern = string.Format( "^{0}$", args[0] );
// convert "DOS format" wildcards to regex formatpattern = pattern.Replace( "*", ".*?" );
Regex regex = new Regex( pattern, RegexOptions.IgnoreCase );
// recalculate required column widthcolumnwidth = 0;
foreach ( string key in sysinfolist.Keys )
{if ( regex.IsMatch( key ) )
{matchfound = true;
columnwidth = Math.Max( columnwidth, key.Length );
} }if ( !matchfound )
{return ShowHelp( "Invalid command line argument \"{0}\"", args[0] );
} // show all matching properties and their valuesforeach ( string key in sysinfolist.Keys )
{if ( regex.IsMatch( key ) )
{matchfound = true;
Console.WriteLine( "{0,-" + columnwidth + "} {1}", key, sysinfolist[key] );
} }return 0;
} else {return ShowHelp( "Invalid command line argument \"{0}\"", args[0] );
}default:
return ShowHelp( "Too many command line arguments" );
} }static int ShowHelp( params string[] errmsg )
{ #region Error Messageif ( errmsg.Length > 0 )
{List<string> errargs = new List<string>( errmsg );
errargs.RemoveAt( 0 );
Console.Error.WriteLine( );
Console.ForegroundColor = ConsoleColor.Red;
Console.Error.Write( "ERROR:\t" );
Console.ForegroundColor = ConsoleColor.White;
Console.Error.WriteLine( errmsg[0], errargs.ToArray( ) );
Console.ResetColor( );
} #endregion Error Message #region Help Text /* GetSystemInformation.exe, Version 1.02 Get properties and values of .NET's System.Windows.Forms.SystemInformation class Usage: GetSystemInformation.exe [ property ] Where: property is the name of the property (or properties) to be queried (wildcard * allowed, e.g. mouse* or *window*) Notes: Without a command line argument, the program will list all properties and values of .NET's System.Windows.Forms.SystemInformation class. If a single property name (no wildcards) is specified on the command line, and its value is numeric, the return code will equal (the integer of) that value, or 0 if the value isn't numeric, or -1 in case of (command line) errors. Written by Rob van der Woude https://www.robvanderwoude.com */Console.Error.WriteLine( );
Console.Error.WriteLine( "GetSystemInformation.exe, Version {0}", progver );
Console.Error.WriteLine( "Get properties and values of .NET's System.Windows.Forms.SystemInformation class" );
Console.Error.WriteLine( );
Console.Error.Write( "Usage: " );
Console.ForegroundColor = ConsoleColor.White;
Console.Error.WriteLine( "GetSystemInformation.exe [ property ]" );
Console.ResetColor( );
Console.Error.WriteLine( );
Console.Error.Write( "Where: " );
Console.ForegroundColor = ConsoleColor.White;
Console.Error.Write( "property" );
Console.ResetColor( );
Console.Error.WriteLine( " is the name of the property (or properties) to be queried" );
Console.Error.WriteLine( " (wildcard * allowed, e.g. mouse* or *window*)" );
Console.Error.WriteLine( );
Console.Error.WriteLine( "Notes: Without a command line argument, the program will list all properties" );
Console.Error.WriteLine( " and values of .NET's System.Windows.Forms.SystemInformation class." );
Console.Error.WriteLine( " If a single property name (no wildcards) is specified on the command" );
Console.Error.WriteLine( " line, and its value is numeric, the return code will equal (the" );
Console.Error.WriteLine( " integer of) that value, or 0 if the value isn't numeric, or -1 in" );
Console.Error.WriteLine( " case of (command line) errors." );
Console.Error.WriteLine( );
Console.Error.WriteLine( "Written by Rob van der Woude" );
Console.Error.WriteLine( "https://www.robvanderwoude.com" );
#endregion Help Textreturn -1;
} }}page last modified: 2025-10-11; loaded in 0.0105 seconds