using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Management; namespace SysSecLibs { public class Utils { public static Array StrToArray(string str) { return StrToArrayEx(str, ","); } /// /// 将一个字符串以分割符转换成Array对象,如 a,[b,[c,d]],e 将分割成 a ; b,[c,d] ; e 三个串 /// /// /// /// public static Array StrToArrayEx(string str, string separator) { ArrayList list1 = new ArrayList(); str = (str == null) ? "" : str.Trim(); int num1 = separator.Length; while (str.Length > 0) { int num2 = str.IndexOf(separator); int num3 = str.IndexOf("["); if ((num3 >= 0) && (num3 < num2)) { int num4 = 1; int num5 = str.Length; int num6 = num3 + 1; while (num6 < num5) { switch (str[num6]) { case '[': num4++; goto Label_0082; case '\\': goto Label_0082; case ']': break; default: goto Label_0082; } num4--; Label_0082: if (num4 == 0) { break; } num6++; } num2 = str.IndexOf(separator, num6); } if (num2 < 0) { num2 = str.Length; } string text1 = str.Substring(0, num2); int num7 = text1.Length; if (((num7 > 0) && (text1[0] == '[')) && (text1[num7 - 1] == ']')) { text1 = text1.Substring(1, num7 - 2); } list1.Add(text1.Trim()); if ((num2 + num1) > str.Length) { str = ""; } else { str = str.Substring(num2 + num1).Trim(); } } Array array1 = Array.CreateInstance(typeof(string), list1.Count); list1.CopyTo(array1); return array1; } public static string GetMachineMac() { string lcRetVal = ""; try { string text2 = "select AdapterType, DeviceID, ProductName, ServiceName, MACAddress from Win32_NetworkAdapter"; WqlObjectQuery query1 = new WqlObjectQuery(text2); ManagementObjectCollection collection1 = new ManagementObjectSearcher(query1).Get(); foreach (ManagementObject obj1 in collection1) { lcRetVal += ((lcRetVal == "") ? "" : ",") + obj1["MACAddress"]; } return lcRetVal; } catch (Exception) { } return lcRetVal; } public static string GetCpuId() { string lcRetVal = ""; try { string text2 = "select CurrentClockSpeed, Name, OtherFamilyDescription, ProcessorId, ProcessorType, SystemName, UniqueId from Win32_Processor"; WqlObjectQuery query1 = new WqlObjectQuery(text2); ManagementObjectCollection collection1 = new ManagementObjectSearcher(query1).Get(); foreach (ManagementObject obj1 in collection1) { lcRetVal = lcRetVal + ((lcRetVal == "") ? "" : ",") + obj1["ProcessorId"]; } return lcRetVal; } catch (Exception) { } return lcRetVal; } } }