System settings through c#

  • Thread starter Thread starter GC
  • Start date Start date
G

GC

Hi,
How would I get various system settings through C# such as machine name,
hard drives, bytes free on hard drives, printers, etc...this is going to be
from a simple console app. Thanks!
 
GC,

In addition to what John Wood mentioned in his post, you might want to
take a look in the System.Management namespace. It will have classes that
allow you to access the WMI classes, which will give you pretty much any
piece of information about the system that you wish.

Hope this helps.
 
Check the System.Windows.Forms.SystemInformation class...

Hi,
How would I get various system settings through C# such as machine name,
hard drives, bytes free on hard drives, printers, etc...this is going to be
from a simple console app. Thanks!
 
Hi,

You can use all of the methods that everyone has provided plus the
System.Environment to get basic information. I have posted a sample below
that shows the System.Environment and the System.Management classes (and a
link to the WMI Properties). From these you should be able to get anything
that you need.

Hope this helps
---------------------

//link for the WMI - Win32_LogicalDisk propertie
//http://msdn.microsoft.com/library/d...s/wmisdk/wmi/win32_logicaldisk.asp?frame=true

//System.Environment information
String env_query = "My system drive is %PATHEXT% and my system root is
%SystemRoot%";
Console.WriteLine(Environment.ExpandEnvironmentVariables(env_query));

//System.Management - WMI Information
String strSQL = "SELECT * FROM Win32_LogicalDisk" ;
SelectQuery mgmt_query = new SelectQuery();
mgmt_query.QueryString = strSQL;
ManagementObjectSearcher searcher = new ManagementObjectSearcher(mgmt_query);
foreach(ManagementObject mo in searcher.Get())
{
if(mo["FreeSpace"] != null)
Console.WriteLine(mo["Name"].ToString() + " " +
mo["FreeSpace"].ToString());
}
 
Back
Top