System and Environment Information Sample
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

System and Environment Information Sample 

Download sample

This sample demonstrates the use of several classes that provide environment information.

Security noteSecurity Note

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

To open the sample file in Solution Explorer

  1. Click Download Sample.

    The File Download message box appears.

  2. Click Open, and on the left column of the zip folder window, click Extract all files.

    The Extraction Wizard opens.

  3. Click Next. You can change the directory that the files will be extracted to, and then click Next again.

  4. Make sure that the Show extracted files check box is selected, and click Finish.

  5. Double-click the sample's .sln file.

    The sample solution is displayed in Solution Explorer. You might get a security warning that says the solution location is not trusted. Click OK to continue.

To run this sample

  • Press F5.


The main form contains one TabControl with several tab pages. Each tab page calls a different group of Environment or SystemInformation members:

  • Properties This tab demonstrates Environment properties.

  • Special folders The code calls the GetNames method on the SpecialFolder to retrieve a list of all the special folder names. This list is used as a data source for the ListBox control.

  • Methods This tab shows results from calling Environment methods, including Exit and ExpandEnvironmentVariables . The string arrays returned by the GetLogicalDrives and GetCommandLineArgs methods are used as data sources to ListBox controls.

  • Environment variables The code calls the GetEnvironmentVariables method. The Keys property of the returned collection is used as the data source for a ListBox control. This tab page also demonstrates retrieving one environment variable by calling the GetEnvironmentVariable method.

  • System information This tab retrieves all the information provided by the SystemInformation.

See Also

© 2015 Microsoft