Using system;
Using system. Management;
Namespace soyee. Comm
{
/// <Summary>
/// Computer Information
/// </Summary>
Public class computer
{
Public String cpuid;
Public String macaddress;
Public String diskid;
Public String IPaddress;
Public String loginusername;
Public String computername;
Public String systemtype;
Public String totalphysicalmemory; // unit: m
Private Static computer _ instance;
Public static computer instance ()
{
If (_ instance = NULL)
_ Instance = new computer ();
Return _ instance;
}
Protected computer ()
{
Cpuid = getcpuid ();
Macaddress = getmacaddress ();
Diskid = getdiskid ();
IPaddress = getipaddress ();
Loginusername = GetUserName ();
Systemtype = getsystemtype ();
Totalphysicalmemory = gettotalphysicalmemory ();
Computername = getcomputername ();
}
String getcpuid ()
{
Try
{
// Obtain the CPU serial number code
String cpuinfo = ""; // CPU serial number
Managementclass MC = new managementclass ("win32_processor ");
Managementobjectcollection MOC = mc. getinstances ();
Foreach (managementobject Mo in MoC)
{
Cpuinfo = Mo. properties ["processorid"]. value. tostring ();
}
MoC = NULL;
MC = NULL;
Return cpuinfo;
}
Catch
{
Return "unknow ";
}
Finally
{
}
}
String getmacaddress ()
{
Try
{
// Obtain the hardware address of the NIC
String MAC = "";
Managementclass MC = new managementclass ("win32_networkadapterconfiguration ");
Managementobjectcollection MOC = mc. getinstances ();
Foreach (managementobject Mo in MoC)
{
If (bool) Mo ["ipenabled"] = true)
{
MAC = Mo ["macaddress"]. tostring ();
Break;
}
}
MoC = NULL;
MC = NULL;
Return MAC;
}
Catch
{
Return "unknow ";
}
Finally
{
}
}
String getipaddress ()
{
Try
{
// Obtain the IP address
String ST = "";
Managementclass MC = new managementclass ("win32_networkadapterconfiguration ");
Managementobjectcollection MOC = mc. getinstances ();
Foreach (managementobject Mo in MoC)
{
If (bool) Mo ["ipenabled"] = true)
{
// St = Mo ["IPaddress"]. tostring ();
System. array Ar;
AR = (system. array) (Mo. properties ["IPaddress"]. value );
St = ar. getvalue (0). tostring ();
Break;
}
}
MoC = NULL;
MC = NULL;
Return st;
}
Catch
{
Return "unknow ";
}
Finally
{
}
}
String getdiskid ()
{
Try
{
// Obtain the hard disk ID
String Hdid = "";
Managementclass MC = new managementclass ("win32_diskdrive ");
Managementobjectcollection MOC = mc. getinstances ();
Foreach (managementobject Mo in MoC)
{
Hdid = (string) Mo. properties ["model"]. value;
}
MoC = NULL;
MC = NULL;
Return Hdid;
}
Catch
{
Return "unknow ";
}
Finally
{
}
}
/// <Summary>
/// Username used to log on to the Operating System
/// </Summary>
/// <Returns> </returns>
String GetUserName ()
{
Try
{
String ST = "";
Managementclass MC = new managementclass ("win32_computersystem ");
Managementobjectcollection MOC = mc. getinstances ();
Foreach (managementobject Mo in MoC)
{
St = Mo ["username"]. tostring ();
}
MoC = NULL;
MC = NULL;
Return st;
}
Catch
{
Return "unknow ";
}
Finally
{
}
}
/// <Summary>
/// Pc type
/// </Summary>
/// <Returns> </returns>
String getsystemtype ()
{
Try
{
String ST = "";
Managementclass MC = new managementclass ("win32_computersystem ");
Managementobjectcollection MOC = mc. getinstances ();
Foreach (managementobject Mo in MoC)
{
St = Mo ["systemtype"]. tostring ();
}
MoC = NULL;
MC = NULL;
Return st;
}
Catch
{
Return "unknow ";
}
Finally
{
}
}
/// <Summary>
/// Physical memory
/// </Summary>
/// <Returns> </returns>
String gettotalphysicalmemory ()
{
Try
{
String ST = "";
Managementclass MC = new managementclass ("win32_computersystem ");
Managementobjectcollection MOC = mc. getinstances ();
Foreach (managementobject Mo in MoC)
{
St = Mo ["totalphysicalmemory"]. tostring ();
}
MoC = NULL;
MC = NULL;
Return st;
}
Catch
{
Return "unknow ";
}
Finally
{
}
}
/// <Summary>
///
/// </Summary>
/// <Returns> </returns>
String getcomputername ()
{
Try
{
Return System. environment. getenvironmentvariable ("computername ");
}
Catch
{
Return "unknow ";
}
Finally
{
}
}
}
}