Some methods used for COM +

Source: Internet
Author: User

// 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 );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.