public static void ProcessHandle(string parametro) { try { parametro = AjustaAspas(parametro); List <HandleProcessItem> lstProcessos = HandleObj.Instance.GetHandles(parametro); if (lstProcessos.Count > 0) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); using (var form = new ExibirProcessosUsoForm(parametro, lstProcessos)) { form.ShowDialog(); } } else { MessageBox.Show($"{parametro}\r\n\r\nNão está em uso.", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception handleEx) { MessageBox.Show("Erro(s) ao verificar uso." + Environment.NewLine + handleEx.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private static void ProcessHandle(ArgsItem argsItem) { try { List <HandleProcessItem> lstProcessos = HandleObj.Instance.GetHandles(argsItem.Parametro); if (lstProcessos.Count > 0) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); using (var form = new ExibirProcessosUsoForm(argsItem.Parametro, lstProcessos)) { form.ShowDialog(); } } else { MessageBox.Show($"{argsItem.Parametro}\r\n\r\nNão está em uso.", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception handleEx) { MessageBox.Show("Erro(s) ao verificar uso." + Environment.NewLine + handleEx.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } /* * string output, outputError; * try * { * int exitCode = CommandClass.ExecuteCommand(fileName, "-a -u -accepteula -nobanner \"" + parametro + "\"", * out output, out outputError, workingDir); * if (exitCode == 0) * { * const string NaoEstaSendoUsado = "No matching handles found"; * if (output.IndexOf(NaoEstaSendoUsado, StringComparison.CurrentCultureIgnoreCase) >= 0) * MessageBox.Show($"{parametro}\r\n\r\nNão está em uso.", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information); * * else * { * List<HandleProcessItem> lstProcessos = HandleProcessItem.ParseOutput(output); * * Application.EnableVisualStyles(); * Application.SetCompatibleTextRenderingDefault(false); * * using (var form = new ExibirProcessosUsoForm(parametro, lstProcessos)) * { * form.ShowDialog(); * } * } * } * else * MessageBox.Show("Erro(s) ao verificar uso." + Environment.NewLine + outputError, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); * } * catch (Exception ex) * { * MessageBox.Show("Erro desconhecido: " + ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); * } */ //var info = new ProcessStartInfo(@"cmd") //{ // RedirectStandardInput = true, // RedirectStandardError = true, // RedirectStandardOutput = true, // UseShellExecute = false, // CreateNoWindow = true, // WorkingDirectory = workingDir, //}; //Process p = Process.Start(info); //p.StandardInput.AutoFlush = true; //p.OutputDataReceived += OnOutputDataReceived; //p.BeginOutputReadLine(); //strOutput = new StringBuilder(); //p.StandardInput.WriteLine("handle.exe -a -u -accepteula -nobanner \"" + parametro + "\""); //p.StandardInput.WriteLine(@"exit"); //bool exited = p.WaitForExit(1000 * 60 * 15); //if (exited) //{ // p.StandardInput.Close(); // p.CancelOutputRead(); //} //else // p.Kill(); //ProcessStartInfo handleParams = new ProcessStartInfo() //{ // FileName = fileName, // WorkingDirectory = workingDir, // Arguments = "-a -u -accepteula -nobanner \"" + parametro + "\"", // UseShellExecute = false, // RedirectStandardOutput = true, // CreateNoWindow = false //}; //Process handleProcess = Process.Start(handleParams); //handleProcess.WaitForExit(); //string output = handleProcess.StandardOutput.ReadToEnd(); //string output = strOutput.ToString(); }