public static List <COMPortInfo> GetCOMPortsInfo() { List <COMPortInfo> comPortInfoList = new List <COMPortInfo>(); ConnectionOptions options = ProcessConnection.ProcessConnectionOptions(); ManagementScope connectionScope = ProcessConnection.ConnectionScope(Environment.MachineName, options, @"\root\CIMV2"); ObjectQuery objectQuery = new ObjectQuery("SELECT * FROM Win32_PnPEntity WHERE ConfigManagerErrorCode = 0"); ManagementObjectSearcher comPortSearcher = new ManagementObjectSearcher(connectionScope, objectQuery); using (comPortSearcher) { string caption = null; foreach (ManagementObject obj in comPortSearcher.Get()) { if (obj != null) { object captionObj = obj["Caption"]; if (captionObj != null) { caption = captionObj.ToString(); if (caption.Contains("(COM")) { COMPortInfo comPortInfo = new COMPortInfo(); comPortInfo.Name = caption.Substring(caption.LastIndexOf("(COM")).Replace("(", string.Empty).Replace(")", string.Empty); comPortInfo.Description = caption; comPortInfoList.Add(comPortInfo); } } } } return(comPortInfoList); } }
public Browser_IE() { options = ProcessConnection.ProcessConnectionOptions(); connectionScope = ProcessConnection.ConnectionScope( Environment.MachineName, options); browserTable.Columns.Add("PID"); browserTable.Columns.Add("Tab Title"); browserTable.Columns.Add("CPU Usage"); }
void buildPrettyNameCache(bool bForce = false) { if (bForce) { _prettyNameCache = null; } if (_prettyNameCache != null) { return; } _prettyNameCache = new Dictionary <string, string>(); ConnectionOptions options = ProcessConnection.ProcessConnectionOptions(); ManagementScope connectionScope = ProcessConnection.ConnectionScope(Environment.MachineName, options, @"\root\CIMV2"); ObjectQuery objectQuery = new ObjectQuery("SELECT * FROM Win32_PnPEntity WHERE ConfigManagerErrorCode = 0"); ManagementObjectSearcher comPortSearcher = new ManagementObjectSearcher(connectionScope, objectQuery); using (comPortSearcher) { string caption = null; int i = 0; foreach (ManagementObject obj in comPortSearcher.Get()) { i++; if (obj != null) { object captionObj = obj["Caption"]; object deviceIdObj = obj["DeviceID"]; if (captionObj != null) { caption = captionObj.ToString(); if (caption.Contains("(COM")) { string name = caption.Substring(caption.LastIndexOf("(COM")).Replace("(", string.Empty).Replace(")", string.Empty); _prettyNameCache.Add(name, caption); } } } } } }
/// <summary> /// Process to check watcher and evaluate what happens based on evaluation. /// </summary> public override void CheckProcess() { bool isOk = true; // Check. isOk = isOk ? (InternetConnection.IsSelected ? InternetConnection.Check() : true) : false; isOk = isOk ? (ProcessConnection.IsSelected ? ProcessConnection.Check() : true) : false; // Failure hook. if (!isOk && !mIsFailureRoutineFired) { mIsFailureRoutineFired = true; // Let know the procedure to do not fire this the same event again until the failure disappear. FailureRoutine.Do(); } // First occurance of recovery from failure. else if (isOk && mIsFailureRoutineFired) { mIsFailureRoutineFired = false; // Reset value back to false to be able to record failure event again when occurs. } }
static void Main(string[] args) { LoggerManager.InitLogger(new LogConfig()); var testIn = @"C:\Users\Administrator\Desktop\应用工具\alihbase-2.0.9\bin\hbase.cmd"; //var testIn = @"E:\WorkSpace\opensource\DCliWrap\CMDDemo\bin\Debug\netcoreapp3.1\CMDDemo.exe"; ProcessConnection processConnection = new ProcessConnection(); processConnection.ConnectionStr = testIn; var connectMsg = processConnection.Open((msg) => { //Console.WriteLine(msg); }, "shell"); Console.WriteLine(connectMsg); while (processConnection.Status != ConnStatus.Disposed) { var cmd = Console.ReadLine(); processConnection.SendDataAsync(cmd); //cli.ExecuteAsync(); } }
public static List <PrinterInfo> GetComDevicesInfo() { var options = ProcessConnection.ProcessConnectionOptions(); var connectionScope = ProcessConnection.ConnectionScope(Environment.MachineName, options, @"\root\CIMV2"); var objectQuery = new ObjectQuery("SELECT Name, Caption FROM Win32_PnPEntity WHERE ConfigManagerErrorCode = 0"); var comPortSearcher = new ManagementObjectSearcher(connectionScope, objectQuery); var comPortDevicesList = new List <PrinterInfo>(); using (comPortSearcher) { foreach (var item in comPortSearcher.Get()) { var deviceCaption = item["Caption"]; if (deviceCaption == null) { continue; } if (!deviceCaption.ToString().Contains("(COM")) { continue; } var comDevice = new PrintUtility.PrinterInfo { Name = item["Name"].ToString(), ComPort = deviceCaption.ToString().Substring(deviceCaption.ToString().LastIndexOf("(COM", StringComparison.Ordinal)).Replace("(", string.Empty).Replace(")", string.Empty) }; comPortDevicesList.Add(comDevice); } } return(comPortDevicesList); }
internal ProcessConnection(string dbName, ProcessConnection next) { this.dbName = dbName; this.next = next; }
private ProcessConnection getProcessConnection(string databaseName) { for (processConnection = processConnections; processConnection != null && !processConnection.isThisDatabase(databaseName); processConnection = processConnection.Next) { ; } if (processConnection == null) { processConnections = processConnection = new ProcessConnection(databaseName, processConnections); } return processConnection; }
/// <summary> /// Gets a list of COMPortInfo objects. This contains a port name and description of every com port in the system, including ones in use. /// </summary> /// <returns></returns> public static List <ComPortInfo> GetDescriptions() { var comPortInfoList = new List <ComPortInfo>(); var options = ProcessConnection.ProcessConnectionOptions(); var connectionScope = ProcessConnection.ConnectionScope(Environment.MachineName, options, @"\root\CIMV2"); var objectQuery = new ObjectQuery("SELECT * FROM Win32_PnPEntity WHERE ClassGuid=\"{4d36e978-e325-11ce-bfc1-08002be10318}\""); var comPortSearcher = new ManagementObjectSearcher(connectionScope, objectQuery); using (comPortSearcher) { foreach (var obj in comPortSearcher.Get()) { if (obj["Caption"]?.ToString().Contains("COM") != true) { continue; } var comPortInfo = new ComPortInfo { Manufacturer = obj["Manufacturer"]?.ToString(), Caption = obj["Caption"]?.ToString(), DeviceId = obj["DeviceID"]?.ToString(), Description = obj["Description"]?.ToString(), Name = obj["Name"]?.ToString() }; comPortInfo.Caption = obj["Caption"]?.ToString(); var tempString = comPortInfo.Caption.Substring(comPortInfo.Caption.IndexOf("(", StringComparison.Ordinal) + 1); tempString = tempString.Substring(0, tempString.IndexOf(")", StringComparison.Ordinal)); comPortInfo.Port = tempString; if (comPortInfo.DeviceId?.Contains("VID") == true) { comPortInfo.Vid = comPortInfo.DeviceId.Substring(comPortInfo.DeviceId.IndexOf("VID", StringComparison.Ordinal) + 4, 4); } if (comPortInfo.DeviceId?.Contains("PID") == true) { comPortInfo.Pid = comPortInfo.DeviceId.Substring(comPortInfo.DeviceId.IndexOf("PID", StringComparison.Ordinal) + 4, 4); } if (comPortInfo.Manufacturer?.Contains("FTDI") == true) { tempString = comPortInfo.DeviceId?.Substring(comPortInfo.DeviceId.IndexOf("PID", StringComparison.Ordinal) + 9); if (tempString != null) { var tempInt = tempString.IndexOf("\\", StringComparison.Ordinal); if (tempInt > 0) { tempString = tempString.Substring(0, tempInt); comPortInfo.Serial = tempString; } } } comPortInfoList.Add(comPortInfo); } } return(comPortInfoList.OrderBy(x => x.Description).ToList()); }
public ProcessLocal() { options = ProcessConnection.ProcessConnectionOptions(); connectionScope = ProcessConnection.ConnectionScope( Environment.MachineName, options); }