// Obtain the CPU serial number
Private 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
{
}
}
// Retrieve all running COM + components and their application IDS
Public void GetCOMPlusApplicationsList ()
{
COMSVCSLib. MtsGrp GrpObj = null;
Type dcomType = Type. GetTypeFromProgID ("mts. MtsGrp ");
Object dcomObj = Activator. CreateInstance (dcomType );
GrpObj = (COMSVCSLib. MtsGrp) dcomObj;
Object obj = null;
COMSVCSLib. COMEvents eventObj = null;
For (int I = 0; I <GrpObj. Count; ++ I)
{
GrpObj. Item (I, out obj );
EventObj = (COMSVCSLib. COMEvents) obj;
AddtoListView (eventObj. GetProcessID (), eventObj. PackageName );
Marshal. ReleaseComObject (obj );
Obj = null;
Marshal. ReleaseComObject (eventObj );
EventObj = null;
}
Marshal. ReleaseComObject (dcomObj );
DcomObj = null;
Return;
}
/**/
/// <Summary>
/// Performance counter, used to obtain the percentage of CPU idle
/// </Summary>
Private static PerformanceCounter mIdle = new PerformanceCounter ("Processor", "% Processor Time", "Idle ");
Private Label label1;
/**/
/// <Summary>
/// Performance counter, used to obtain the total CPU utilization
/// </Summary>
Private static PerformanceCounter mTotal = new PerformanceCounter ("Processor", "% Processor Time", "_ Total ");
String nVal = mTotal. NextValue (). ToString ();
// PerformanceCounter cpuCounter;
// PerformanceCounter ramCounter;
// CpuCounter = new PerformanceCounter ();
// CpuCounter. CategoryName = "Processor ";
// CpuCounter. CounterName = "% Processor Time ";
// CpuCounter. InstanceName = "_ Total ";
// RamCounter = new PerformanceCounter ("Memory", "Available MBytes ");
// Path of the current program
System. AppDomain. CurrentDomain. BaseDirectory. ToString ();
// Save the file
SaveFileDialog sf = new SaveFileDialog ();
// Set the file storage type
Sf. Filter = "txt file | *. txt | all files | *.*";
// If the user does not enter the extension, the suffix is automatically appended.
Sf. AddExtension = true;
// Set the title
Sf. Title = "Writing Files ";
// If the user clicks the Save button
If (sf. ShowDialog () = DialogResult. OK)
{
This.txt FilePath. Text = sf. FileName;
}
System. IO. StreamWriter f2 = new System. IO. StreamWriter (path, true, System. Text. Encoding. UTF8 );
F2.WriteLine (txtStrings );