public void Collect(IDataCollector collector) { collector.CreateFileEntry("Services.csv"); try { collector.CurrentState = String.Empty; StreamWriter writer = new StreamWriter(collector.Stream); bool isRunFirst = true; using (var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Service")) { foreach (ManagementBaseObject obj in searcher.Get()) { if (isRunFirst) { foreach (PropertyData property in obj.Properties) { if (!IsDisplay(property)) continue; writer.Write(property.Name); writer.Write(Consts.CsvSeparator); } writer.WriteLine(); isRunFirst = false; } foreach (PropertyData property in obj.Properties) { if (!IsDisplay(property)) continue; writer.Write(property.Value); writer.Write(Consts.CsvSeparator); } writer.WriteLine(); collector.CheckIsStop(); } } } catch (AbortException) { throw; } catch (Exception ex) { collector.ShowException(ex); } finally { collector.CloseFileEntry(); } }
public void Collect(IDataCollector collector) { collector.CreateFileEntry("Msinfo.nfo"); try { collector.CurrentState = String.Empty; string fileName = Path.GetTempPath() + "msinfo.nfo"; Process process = Process.Start("msinfo32.exe", "/nfo " + String.Format("\"{0}\"", fileName)); if (process == null) throw new ApplicationException("Cannot start Msinfo32"); while (!process.WaitForExit(100)) collector.CheckIsStop(); if (!File.Exists(fileName)) throw new ApplicationException("Msinfo32 is failed or cancelled"); using (Stream fileStream = File.OpenRead(fileName)) StreamUtils.Copy(fileStream, collector.Stream, new byte[4096]); try { File.Delete(fileName); } catch { } } catch (AbortException) { throw; } catch (Exception ex) { collector.ShowException(ex); } finally { collector.CloseFileEntry(); } }
private void CollectDrive(string drive, IDataCollector collector) { _directories.Clear(); _directories.Push(drive); while (_directories.Count > 0) { string currDir = _directories.Pop(); try { foreach (string file in Directory.GetFiles(currDir)) { try { CollectFile(file); } catch (Exception ex) { if (!IsValidException(ex)) throw; WriteError(currDir, ex); } } foreach (string dir in Directory.GetDirectories(currDir)) _directories.Push(dir); } catch (Exception ex) { if (!IsValidException(ex)) throw; WriteError(currDir, ex); } collector.CurrentState = currDir; collector.CheckIsStop(); } }
private void CollectRootKey(RegistryKey key, IDataCollector collector) { _keys.Clear(); _keys.Push(key); while (_keys.Count > 0) { RegistryKey currKey = _keys.Pop(); if (currKey == null) continue; string currKeyName = currKey.ToString(); collector.CurrentState = currKeyName; CollectKey(currKeyName, String.Empty); foreach (string keyName in currKey.GetSubKeyNames()) { try { _keys.Push(currKey.OpenSubKey(keyName)); } catch (Exception ex) { if (!IsValidException(ex)) throw; CollectKey(currKey + "\\" + keyName, ex.Message); } } currKey.Close(); collector.CheckIsStop(); } }