/// <summary> /// /// </summary> public WmicWorker(WmicContext context, QueryType queryFlags) { // Create the queries to run based off the context and flags if (queryFlags.HasFlag(QueryType.Software)) { if (queryFlags.HasFlag(QueryType.SoftwareVersion)) { this.queries.Add(new SoftwareVersionQuery(context)); } else { this.queries.Add(new SoftwareQuery(context)); } } if (queryFlags.HasFlag(QueryType.ComputerModel)) { this.queries.Add(new ModelQuery(context)); } if (queryFlags.HasFlag(QueryType.SerialNumber)) { this.queries.Add(new SerialNumberQuery(context)); } }
static void Main(string[] args) { WmicContext context = new WmicContext(); context.MachineName = "Thor"; context.Password = "******"; context.Username = "******"; QueryType type = QueryType.ComputerModel | QueryType.Software | QueryType.SoftwareVersion; WmicWorker worker = new WmicWorker(context, type); worker.OnQueryCompleted += () => { Console.WriteLine("Finished"); }; worker.Go(); Console.ReadLine(); }
public BaseQuery(WmicContext context) { StringBuilder sb = new StringBuilder(); sb.Append("/c wmic"); if (!context.MachineName.Equals(Environment.MachineName, StringComparison.OrdinalIgnoreCase)) { sb.Append(@" /node:"); sb.Append(context.MachineName); sb.Append(@" /user:"******"\"); sb.Append(context.Username); sb.Append(" /password:\""); sb.Append(context.Password); sb.Append("\""); } queryText = sb.ToString(); }
public SoftwareVersionQuery(WmicContext context) : base(context) { queryText = base.QueryText + " product get name, version"; }
public ModelQuery(WmicContext context) : base(context) { queryText = base.QueryText + " csproduct get name"; }
public SoftwareQuery(WmicContext context) : base(context) { queryText = base.QueryText + " product get name"; }
public SerialNumberQuery(WmicContext context) : base(context) { queryText = base.QueryText + " bios get serialnumber"; }