public override void Run(string deviceClass) { ObjectQuery query = new ObjectQuery(String.Format( "select * from {0} where DeviceClass='{1}' and DeviceName is not null and DriverVersion is not null", WmiClass.PnPSignedDriver, deviceClass.ToUpper())); remoteComputer.Log("Querying " + deviceClass + " drivers..."); try { using (var wmiObjectSearcher = new ManagementObjectSearcher(mgmtClass.Scope, query)) { foreach (var item in wmiObjectSearcher.Get()) { remoteComputer.Log((string)item["DeviceName"] + " " + (string)item["DriverVersion"], false); } } } catch (Exception ex) { DebugLog.DebugLog.Log("Error when executing WMI query/method on " + remoteComputer.ipAddressStr + ": " + ex); remoteComputer.Log("Error: " + ex.Message); WmiConnectionHandler.AttemptReconnect(mgmtClass.Scope); } remoteComputer.Log("End of " + deviceClass + " drivers." + Environment.NewLine); }
public override void Run(string[] parameters) { ObjectQuery query = new ObjectQuery(BuildQueryString(parameters)); remoteComputer.Log("Querying Event Viewer..."); try { using (var wmiObjectSearcher = new ManagementObjectSearcher(mgmtClass.Scope, query)) { foreach (var item in wmiObjectSearcher.Get()) { DateTime date = ManagementDateTimeConverter.ToDateTime( item["TimeGenerated"].ToString()); remoteComputer.Log( "Event ID: " + (UInt16)item["EventCode"] + Environment.NewLine + "Time Generated: " + date + Environment.NewLine + "Message: " + (string)item["Message"] + Environment.NewLine, false); } } } catch (Exception ex) { DebugLog.DebugLog.Log(string.Format("Error when executing WMI query/method on {0}: {1}", remoteComputer.ipAddressStr, ex)); remoteComputer.Log("Error: " + ex.Message); WmiConnectionHandler.AttemptReconnect(mgmtClass.Scope); } remoteComputer.Log("End events." + Environment.NewLine); }
public override void Run() { ObjectQuery query = new ObjectQuery(String.Format("select * from {0}", WmiClass.Product)); remoteComputer.Log("Querying installed programs..."); try { using (var wmiObjectSearcher = new ManagementObjectSearcher(mgmtClass.Scope, query)) { foreach (var item in wmiObjectSearcher.Get()) { string productName = (string)item["Caption"]; if (productName != null) { remoteComputer.Log(productName, false); } } } } catch (Exception ex) { DebugLog.DebugLog.Log(string.Format("Error when executing WMI query/method on {0}: {1}", remoteComputer.ipAddressStr, ex)); remoteComputer.Log("Error: " + ex.Message); WmiConnectionHandler.AttemptReconnect(mgmtClass.Scope); } remoteComputer.Log("End of installed programs." + Environment.NewLine); }
public override void Run(string command) { string outputFilePath = @"\\" + remoteComputer.ipAddressStr + @"\C$\" + Path.GetRandomFileName(); string fullCommand = "cmd /c \"" + command + " 1> " + outputFilePath + " 2>&1\""; try { var inParams = mgmtClass.GetMethodParameters("Create"); inParams["CommandLine"] = fullCommand; var outParams = mgmtClass.InvokeMethod("Create", inParams, null); if (int.Parse(outParams["ReturnValue"].ToString()) != 0) { remoteComputer.Log("The command '" + command + "' returned value " + outParams["ReturnValue"] + "."); } else { remoteComputer.Log("The command '" + command + "' executed without errors. (This only means the program did not return an error code.) Please wait up to 60 seconds for output."); } } catch (Exception ex) { DebugLog.DebugLog.Log(string.Format("Error when executing WMI query/method on {0}: {1}", remoteComputer.ipAddressStr, ex)); remoteComputer.Log("There was a problem executing the task: " + ex.Message); WmiConnectionHandler.AttemptReconnect(mgmtClass.Scope); } ReadPrintDelete(outputFilePath, 60); }
public override void Run(string powerPlanName) { try { ActivatePlan(powerPlanName); ValidateActivePlan(powerPlanName); } catch (Exception ex) { DebugLog.DebugLog.Log(string.Format("Error when executing WMI query/method on {0}: {1}", remoteComputer.ipAddressStr, ex)); remoteComputer.Log("Error: " + ex.Message); WmiConnectionHandler.AttemptReconnect(mgmtClass.Scope); } }
public override void Run() { ObjectQuery query = new ObjectQuery(String.Format("select * from {0}", WmiClass.LocalTime)); try { using (var wmiObjectSearcher = new ManagementObjectSearcher(mgmtClass.Scope, query)) { foreach (var item in wmiObjectSearcher.Get()) { remoteComputer.Log(FormatDateTime(wmiObjectSearcher, query) + Environment.NewLine); } } } catch (Exception ex) { DebugLog.DebugLog.Log(string.Format("Error when executing WMI query/method on {0}: {1}", remoteComputer.ipAddressStr, ex)); remoteComputer.Log("Error: " + ex.Message); WmiConnectionHandler.AttemptReconnect(mgmtClass.Scope); } }
public override void Run() { ObjectQuery query = new ObjectQuery(String.Format("select * from {0}", WmiClass.ComputerSystemProduct)); try { using (var wmiObjectSearcher = new ManagementObjectSearcher(mgmtClass.Scope, query)) { foreach (var item in wmiObjectSearcher.Get()) { string name = (string)item["Name"]; string vendor = (string)item["Vendor"]; remoteComputer.Log(name + " " + vendor + Environment.NewLine); } } } catch (Exception ex) { DebugLog.DebugLog.Log(string.Format("Error when executing WMI query/method on {0}: {1}", remoteComputer.ipAddressStr, ex)); remoteComputer.Log("Error: " + ex.Message); WmiConnectionHandler.AttemptReconnect(mgmtClass.Scope); } }
public override void Run(string newHostname) { remoteComputer.Log("Attempting to rename computer from " + remoteComputer.hostname + " to " + newHostname + "."); try { using (var cs = new ManagementObject("Win32_ComputerSystem.Name='" + remoteComputer.hostname + "'")) { cs.Get(); var inParams = cs.GetMethodParameters("Rename"); inParams.SetPropertyValue("Name", newHostname); var outParams = cs.InvokeMethod("Rename", inParams, null); remoteComputer.Log("You must restart this machine for the change to take effect."); } } catch (Exception ex) { DebugLog.DebugLog.Log(string.Format("Error when executing WMI query/method on {0}: {1}", remoteComputer.ipAddressStr, ex)); remoteComputer.Log("Error: You must be able to ping '" + remoteComputer.hostname + "'. Message: " + ex.Message); WmiConnectionHandler.AttemptReconnect(mgmtClass.Scope); } }
public override void Run() { ObjectQuery query = new ObjectQuery(String.Format("select EstimatedChargeRemaining, Status, BatteryStatus from {0}", WmiClass.Battery)); try { using (var wmiObjectSearcher = new ManagementObjectSearcher(mgmtClass.Scope, query)) { foreach (var item in wmiObjectSearcher.Get()) { UInt16 statusCode = (UInt16)item["BatteryStatus"]; remoteComputer.Log("Battery: " + ((UInt16)item["EstimatedChargeRemaining"]).ToString() + "% remaining. Status: " + GetBatteryStatusMessage(statusCode) + Environment.NewLine); } } } catch (Exception ex) { DebugLog.DebugLog.Log(string.Format("Error when executing WMI query/method on {0}: {1}", remoteComputer.ipAddressStr, ex)); remoteComputer.Log("Error: " + ex.Message); WmiConnectionHandler.AttemptReconnect(mgmtClass.Scope); } }
public override void Run() { ObjectQuery query = new ObjectQuery(String.Format("select * from {0}", WmiClass.OS)); try { using (var wmiObjectSearcher = new ManagementObjectSearcher(mgmtClass.Scope, query)) { foreach (var item in wmiObjectSearcher.Get()) { DateTime date = ManagementDateTimeConverter.ToDateTime((string)item["InstallDate"]); remoteComputer.Log((string)item["Caption"] + " " + (string)item["OSArchitecture"] + " (Installed " + date + ")" + Environment.NewLine); } } } catch (Exception ex) { DebugLog.DebugLog.Log(string.Format("Error when executing WMI query/method on {0}: {1}", remoteComputer.ipAddressStr, ex)); remoteComputer.Log("Error: " + ex.Message); WmiConnectionHandler.AttemptReconnect(mgmtClass.Scope); } }
public override void Run() { ObjectQuery query = new ObjectQuery( String.Format("select * from {0} where MACAddress is not null", WmiClass.NetworkConfig)); remoteComputer.Log("Querying network information..."); try { using (var wmiObjectSearcher = new ManagementObjectSearcher(mgmtClass.Scope, query)) { foreach (var item in wmiObjectSearcher.Get()) { remoteComputer.Log(BuildDataString(item), false); } } } catch (Exception ex) { DebugLog.DebugLog.Log(string.Format("Error when executing WMI query/method on {0}: {1}", remoteComputer.ipAddressStr, ex)); remoteComputer.Log("Error: " + ex.Message); WmiConnectionHandler.AttemptReconnect(mgmtClass.Scope); } remoteComputer.Log("End of network information." + Environment.NewLine); }