2015-06-09 2 views
0

Я использую ядро ​​Fiddler, в котором, когда я нажимаю «t» для Trust Root Certificate, он показывает DialogBox «Предупреждение безопасности», чтобы нажать Да или Нет.Как автоматически щелкнуть диалоговое окно, открытое из консольного приложения

Я хочу автоматизировать этот раздел, когда при открытии диалогового окна мое консольное приложение автоматически нажимает Да.

+0

Кажется мне, что вам нужно что-то вроде этого: http://stackoverflow.com/questions/20269616/handle-popup-automatically-and-click-yes-with-findwindow-in-vb- сеть – vesan

ответ

1

Если вы хотите нажать на кнопку в другом окне - сначала найдите название и название класса. Это можно сделать с помощью Spy ++, который находится в папке стартового меню (Microsoft Visual Studio 2010/Visual Studio Tools/Spy ++). В spy ++ просто нажмите Search/find window ..., а не укажите желаемое окно.

И теперь вы можете послать ключ «ввести» в окно (или «вкладки» первого посыла, если [нет] кнопка активна)

Вот ссылка How to: Simulate Mouse and Keyboard Events in Code

пример (отлично работает с моим светлячок):

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Runtime.InteropServices; 

namespace Temp 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      bool IsDone = false; 

      while (IsDone == false) 
      { 
       // Get a handle to the Firefox application. The window class 
       // and window name were obtained using the Spy++ tool. 
       IntPtr firefoxHandle = FindWindow("MozillaWindowClass", null); 

       // Verify that Firefox is a running process. 
       if (firefoxHandle == IntPtr.Zero) 
       { 
        // log of errors 
        Console.WriteLine("Firefox is not running."); 

        // wait 1 sec and retry 
        System.Threading.Thread.Sleep(1000); 
        continue; 
       } 

       // Make Firefox the foreground application and send it commands 
       SetForegroundWindow(firefoxHandle); 

       // send keys to window 
       System.Windows.Forms.SendKeys.SendWait("google.com"); 
       System.Windows.Forms.SendKeys.SendWait("{tab}"); 
       System.Windows.Forms.SendKeys.SendWait("{enter}"); 

       // yeah ! job's done 
       IsDone = true; 
      } 
     } 

     // Get a handle to an application window. 
     [DllImport("USER32.DLL", CharSet = CharSet.Unicode)] 
     public static extern IntPtr FindWindow(string lpClassName, 
      string lpWindowName); 

     // Activate an application window. 
     [DllImport("USER32.DLL")] 
     public static extern bool SetForegroundWindow(IntPtr hWnd); 
    } 
} 
Смежные вопросы