/// <summary> /// 获取全部USB设备列表(带状态,根据STATUS命令) /// </summary> /// <returns></returns> public static List <USBDeviceModel> AllByStatus() { List <USBDeviceModel> list = null; List <string> temp = new List <string>(); Process process = ProcessStarter.NewProcess(DevconExeSelector.GetExe(), " STATUS USB*"); ProcessTool.SleepKill(process, 5); ProcessStarter.Execute(process, new Action <string>((x) => { temp.Add(x); })); if (ListTool.HasElements(temp)) { string inline = string.Join("||||", temp); string[] inlines = inline.Split(new string[] { "USB\\" }, StringSplitOptions.RemoveEmptyEntries); if (ListTool.HasElements(inlines)) { list = new List <USBDeviceModel>(); foreach (var item in inlines) { var usb = USBDeviceModel.String2ModelByStatus(item); if (usb != null) { list.Add(usb); } } } } return(list); }
/// <summary> /// 启用USB设备 /// </summary> /// <returns></returns> public static bool Enable(string id) { List <string> temp = new List <string>(); Process process = ProcessStarter.NewProcess(DevconExeSelector.GetExe(), $" ENABLE \"USB\\{id}\"", R.Domain, R.Username, R.Password); ProcessTool.SleepKill(process, 5); ProcessStarter.Execute(process, new Action <string>((x) => { temp.Add(x); })); if (ListTool.HasElements(temp)) { foreach (var item in temp) { if (Str.Ok(item) && item.ToUpper().StartsWith($"USB\\{id}") && item.ToUpper().Contains("ENABLE")) { return(true); } } } return(false); }