void refreshProcess() { ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Process"); foreach (ManagementObject manObj in searcher.Get()) { if (!IsExistInfoUnit(array, Convert.ToInt32(manObj["ProcessID"]))) { ProcessInfoUnit unitInfo = new ProcessInfoUnit(); unitInfo.ProcessID = int.Parse(manObj["ProcessID"].ToString()); if (manObj["Caption"] != null) unitInfo.Caption = manObj["Caption"].ToString(); if (manObj["CommandLine"] != null) unitInfo.CommandLine = manObj["CommandLine"].ToString(); if (manObj["CreationDate"] != null) { string date = manObj["CreationDate"].ToString(); date = date.Substring(0, 4) + "-" + date.Substring(4, 2) + "-" + date.Substring(6, 2) + " " + date.Substring(8, 2) + ":" + date.Substring(10, 2) + ":" + date.Substring(12, 2); unitInfo.CreationDate = DateTime.Parse(date); } array.Add(unitInfo); } } searcher.Dispose(); }
void refreshProcess() { ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Process"); foreach (ManagementObject manObj in searcher.Get()) { if (!IsExistInfoUnit(array, Convert.ToInt32(manObj["ProcessID"]))) { ProcessInfoUnit unitInfo = new ProcessInfoUnit(); unitInfo.ProcessID = int.Parse(manObj["ProcessID"].ToString()); if (manObj["Caption"] != null) { unitInfo.Caption = manObj["Caption"].ToString(); } if (manObj["CommandLine"] != null) { unitInfo.CommandLine = manObj["CommandLine"].ToString(); } if (manObj["CreationDate"] != null) { string date = manObj["CreationDate"].ToString(); date = date.Substring(0, 4) + "-" + date.Substring(4, 2) + "-" + date.Substring(6, 2) + " " + date.Substring(8, 2) + ":" + date.Substring(10, 2) + ":" + date.Substring(12, 2); unitInfo.CreationDate = DateTime.Parse(date); } array.Add(unitInfo); } } searcher.Dispose(); }