• Process使用


         public static string RunCmd(string cmd)
           {
               cmd = cmd.Trim().TrimEnd('&') + "&exit";
               string output = "";
               using (Process p = new Process())
               {
                   p.StartInfo.FileName = CmdPath;
                   p.StartInfo.UseShellExecute = false;       
                   p.StartInfo.RedirectStandardInput = true;  
                   p.StartInfo.RedirectStandardOutput = true;  
                   p.StartInfo.RedirectStandardError = true;  
                   p.StartInfo.CreateNoWindow = true;         
                   p.Start();
    
                 
                   p.StandardInput.WriteLine(cmd);
                   p.StandardInput.AutoFlush = true;
    
                 
                   output = p.StandardOutput.ReadToEnd();
                   p.WaitForExit();
                   p.Close();
               }
    
               string txt = output;
               return txt;
           }
     #region cmd命令调用
    
            public void StartCmdEvent(string c, HashListItem item)
            {
                Process p = new Process();
                ProcessStartInfo psi = new ProcessStartInfo();
                psi.WorkingDirectory = Path.GetDirectoryName(ExePath);
                psi.FileName = ExePath;
                psi.Arguments = c;
                psi.CreateNoWindow = true;
                psi.UseShellExecute = false;
                psi.RedirectStandardOutput = true;
                psi.RedirectStandardError = true;
                p.OutputDataReceived += P_OutputDataReceived;
                p.EnableRaisingEvents = true;                      // 启用Exited事件  
                p.Exited += new EventHandler(CmdProcess_Exited);   // 注册进程失败事件  
                p.StartInfo = psi;
                item.WorkStatus = HashListItem.Status.Running;
                p.Start();
                p.BeginOutputReadLine();
                p.BeginErrorReadLine();
            }
    
    //退出
    private void CmdProcess_Exited(object sender, EventArgs e) { Process p = sender as Process; }

    //输出 private void P_OutputDataReceived(object sender, DataReceivedEventArgs e) { Process p = sender as Process; } #endregion

    ProcessStartInfo psi = new ProcessStartInfo();
                        psi.FileName = hashcatFile;
                     
                        string hash = radioButton1.Checked ? textBox1.Text : HashfileTextbox.Text;
                        string ss = " -m " + hashType + " -a " + attackMode + " -i --increment-min " + BruteforceMinUpDown.Value.ToString() + " --increment-max " + BruteforceMaxUpDown.Value.ToString() + " -o " + hashcatLoc + "cracked/" + timestamp + ".cracked " + hash;
                        psi.Arguments = " -m " + hashType +" -a " + attackMode +" -i --increment-min " + BruteforceMinUpDown.Value.ToString() +" --increment-max " + BruteforceMaxUpDown.Value.ToString() +" -o " + hashcatLoc +"cracked/" + timestamp +".cracked " + hash;
                        p.StartInfo = psi;
                        p.StartInfo.UseShellExecute = false;
                        p.StartInfo.RedirectStandardOutput = true;
                        p.StartInfo.RedirectStandardInput = true;
                        p.StartInfo.CreateNoWindow = true;
                        p.Start();
                        StreamWriter inputWriter = p.StandardInput;
                        Invoker.SetText(metroLabel6, "No speed data available...");
                        Invoker.SetText(metroLabel7, "");
                        while (!p.StandardOutput.EndOfStream)
                        {
                            string standard_output = p.StandardOutput.ReadLine();

                            if (standard_output.StartsWith("Speed"))
                            {
                                Invoker.SetText(metroLabel6,"Speed:" + Core.StringBetween(":"," (", standard_output));
                            }
                            else if (standard_output.StartsWith("Guess.Mask"))
                            {
                                Invoker.SetText(metroLabel7,"Cracking length:" + Core.StringBetween("[","]", standard_output));
                            }
                        }

                        p.WaitForExit();

  • 相关阅读:
    LTPA Cookie原理
    如何对更改internet密码所需的缓存时间进行调整?
    Freemem eclipse查看内存的小插件
    Java中static、final用法小结
    MANIFEST.MF内容属性名详细解释
    Java程序员的良药:应用程序的开发技巧
    spring struts2 ibatis框架整合开发
    java中静态代码块的用法 static用法详解 类的加载顺序
    从svn上直接导入项目到workspace中
    Eclipse自动生成UML图 Green UML和ModelGoon(直接推拽)
  • 原文地址:https://www.cnblogs.com/qc-id-01/p/8309411.html
Copyright © 2020-2023  润新知