//獲取CPU的序列號
private string GetCpuID()
{
try
{
//獲取CPU序列號代碼
string cpuInfo = "";//cpu序列號
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
{
}
}
//檢索所有正在運行的COM+組件,和它們的應用程序ID
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>
/// 性能計數器,用於獲取CPU空閒百分比
/// </summary>
private static PerformanceCounter mIdle = new PerformanceCounter("Processor", "% Processor Time", "Idle");
private Label label1;
/**/
/// <summary>
/// 性能計數器,用於獲取CPU總利用率
/// </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");
//當前程序的路徑
System.AppDomain.CurrentDomain.BaseDirectory.ToString();
//保存文件
SaveFileDialog sf = new SaveFileDialog();
//設置文件保存類型
sf.Filter = "txt文件|*.txt|所有文件|*.*";
//如果用戶沒有輸入擴展名,自動追加後綴
sf.AddExtension = true;
//設置標題
sf.Title = "寫文件";
//如果用戶點擊了保存按鈕
if (sf.ShowDialog() == DialogResult.OK)
{
this.txtFilePath.Text = sf.FileName;
}
System.IO.StreamWriter f2 = new System.IO.StreamWriter(path, true, System.Text.Encoding.UTF8);
f2.WriteLine(txtStrings);