C#得到系统信息

//cpu频率

using  Microsoft.Win32;

private   int  GetCPUFrequency() 
        {
            RegistryKey rk 
=  Registry.LocalMachine.OpenSubKey( @" HARDWARE\DESCRIPTION\System\CentralProcessor\0 " );

            
object  obj  =  rk.GetValue( " ~MHz " );
            
int  CPUFrequency  =  ( int )obj;
            
return  CPUFrequency; 
        }

//////////////////////////////////

//磁盘空间 Management

using  System.Management;

private   long  GetFreeDiskSpace()
            {
                ManagementObject disk 
=   new  ManagementObject(
                    
" win32_logicaldisk.deviceid=\ " d:\ "" );
                disk.Get();
                
string  totalByte  =  disk[ " FreeSpace " ].ToString();
                
long  freeDiskSpaceMb  =  Convert.ToInt64(totalbyte) / 1024 / 1024 ;
                
return  freeDiskSpaceMb;
            }

 

/////////////////////
//内存信息

using  System;
using  System.Text;
using  System.Runtime.InteropServices;

namespace  ConsoleApplication1
ExpandedBlockStart.gifContractedBlock.gif
{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
    
/// Summary description for Class1.
    
/// </summary>

        
        
class Class1
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            [StructLayout(LayoutKind.Sequential)] 
                
public struct MEMORY_INFO 
ExpandedSubBlockStart.gifContractedSubBlock.gif            

                
public uint dwLength; 
                
public uint dwMemoryLoad; 
                
public uint dwTotalPhys; 
                
public uint dwAvailPhys; 
                
public uint dwTotalPageFile; 
                
public uint dwAvailPageFile; 
                
public uint dwTotalVirtual; 
                
public uint dwAvailVirtual; 
            }

            [DllImport(
"kernel32")] 
            
public static extern void GlobalMemoryStatus(ref MEMORY_INFO meminfo);

            
public static int Main(string[] args) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                Class1 class1 
= new Class1();

                class1.GetMemoryStatus();
                
return 0;
            }

            
private void GetMemoryStatus()
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                MEMORY_INFO MemInfo;
                MemInfo 
= new MEMORY_INFO();
                GlobalMemoryStatus(
ref MemInfo);

                
long totalMb = Convert.ToInt64( MemInfo.dwTotalPhys.ToString())/1024/1024;
                
long avaliableMb = Convert.ToInt64( MemInfo.dwAvailPhys.ToString())/1024/1024;

                Console.WriteLine( 
"物理内存共有" + totalMb + " MB");
                Console.WriteLine( 
"可使用的物理内存有" + avaliableMb +" MB");
            }


        }

//////////////////////////////

//cpu名字

using  Microsoft.Win32;
private   string  GetCPUName() 
            {
                RegistryKey rk 
=  Registry.LocalMachine.OpenSubKey( @" HARDWARE\DESCRIPTION\System\CentralProcessor\0 " );

                
object  obj  =  rk.GetValue( " ProcessorNameString " );
                
string  CPUName  =  ( string )obj;
                
return  CPUName.TrimStart(); 
            }

 

///////////////////////
//OS版本

using  System;

namespace  determineOS_CS
ExpandedBlockStart.gifContractedBlock.gif
{  
class Class1
ExpandedSubBlockStart.gifContractedSubBlock.gif   
{
      
static void Main(string[] args)
ExpandedSubBlockStart.gifContractedSubBlock.gif      
{
         
// Get OperatingSystem information from the system namespace.
         System.OperatingSystem osInfo =System.Environment.OSVersion;
         
         
// Determine the platform.
         switch(osInfo.Platform)
ExpandedSubBlockStart.gifContractedSubBlock.gif         
{
            
// Platform is Windows 95, Windows 98, 
            
// Windows 98 Second Edition, or Windows Me.
            case System.PlatformID.Win32Windows:
         
               
switch (osInfo.Version.Minor)
ExpandedSubBlockStart.gifContractedSubBlock.gif               
{
                  
case 0:
                     Console.WriteLine (
"Windows 95");
                     
break;
                  
case 10:
                     
if(osInfo.Version.Revision.ToString()=="2222A")
                        Console.WriteLine(
"Windows 98 Second Edition");
                     
else
                        Console.WriteLine(
"Windows 98");
                     
break;
                  
case  90:
                     Console.WriteLine(
"Windows Me");
                     
break;
               }

               
break;
         
            
// Platform is Windows NT 3.51, Windows NT 4.0, Windows 2000,
            
// or Windows XP.
            case System.PlatformID.Win32NT:

               
switch(osInfo.Version.Major)

ExpandedSubBlockStart.gifContractedSubBlock.gif               
{
                  
case 3:
                     Console.WriteLine(
"Windows NT 3.51");
                     
break;
                  
case 4:
                     Console.WriteLine(
"Windows NT 4.0");
                     
break;
                  
case 5:
                     
if (osInfo.Version.Minor==0
                        Console.WriteLine(
"Windows 2000");
                     
else
                        Console.WriteLine(
"Windows XP");
                     
break;
               }
break;
         }

         Console.ReadLine ();
      }

   }

}

转载于:https://www.cnblogs.com/wolfcool/archive/2009/06/08/1498501.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值