首页 文章

将CMD输出复制到剪贴板

提问于
浏览
4

我正在尝试将运行CMD提示的程序的输出复制到Windows剪贴板 .

private void button1_Click(object sender, EventArgs e)
            {
            /*Relevant Code*/
            Process p = new Process();
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.FileName = "cmd.exe";
            p.StartInfo.Arguments = String.Format("/k cd {0} && backdoor -rt -on -s{1} -p{2}", backdoorDir, pSN, sPPC);
            p.Start();

            p.WaitForExit();
            string result = p.StandardOutput.ReadToEnd();
            System.Windows.Forms.Clipboard.SetText(result);
            }

如果我直接将其输入CMD,它将如下所示:

第一个命令(更改目录):

cd C:\users\chris\appdata\roaming\backdoor

第二个命令(启动后门,一个cmd工具 . 参数如下 . ):

backdoor -rt -on -sCCDXE -p14453

当通过CMD执行此操作时,我得到以下结果:

The backdoor password is: 34765

C:\users\chris\appdata\roaming\backdoor>

但是,在运行我的C#代码时,这是唯一添加到剪贴板的东西:

C:\users\chris\appdata\roaming\backdoor>

为什么't it capturing 2820775 It'喜欢 p.StandardOutput.ReadToEnd() 并没有阅读所有内容 .

2 回答

  • 2

    WaitForExit 之前致电 ReadToEnd

    克里斯的代码:

    private void button1_Click(object sender, EventArgs e)
        {
            /*Relevant Code*/
            Process p = new Process();
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.FileName = "cmd.exe";
            p.StartInfo.Arguments = String.Format("/k cd {0} && backdoor -rt -on -s{1} -p{2}", backdoorDir, pSN, sPPC);
            p.Start();
    
            string result = p.StandardOutput.ReadToEnd();
            p.WaitForExit();
            System.Windows.Forms.Clipboard.SetText(result);
        }
    

    示例控制台应用代码:

    Process p = new Process();
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.FileName = "cmd.exe";
            p.StartInfo.Arguments = "/C dir";
            p.Start();
    
            string result = p.StandardOutput.ReadToEnd();
            p.WaitForExit();
            Console.WriteLine(result);
            Console.ReadLine();
    
    • 参数 /C 执行该命令,然后终止cmd进程 . 这是此代码工作所必需的 . 否则,它将永远等待 .
  • 2

    一个共鸣 may 好吧,该程序实际上是 not ,而是直接写入屏幕 .

    通过将输出传递到文件来测试它:

    backdoor -rt -on -sCCDXE -p14453 > c:\text.txt
    

    如果新文件不包含输出,那么您将被卡住,可能需要查看屏幕抓取..

相关问题