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();

posted on 2018-01-18 11:46 高软玩家 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/qc-id-01/p/8309411.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值