Example #1
0
        /// <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);
        }
Example #2
0
        /// <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);
        }
Example #3
0
        /// <summary>
        /// 结束超时 Devcon 工具进程
        /// </summary>
        /// <param name="second">超时时间(单位:秒)</param>
        public static void Kills(int second = 5)
        {
            string file = DevconExeSelector.GetExe();
            string name = Path.GetFileNameWithoutExtension(file);

            Azylee.Core.ProcessUtils.ProcessTool.Kills(name, file, second);
        }