Auto-entry of a password in a modal dialog box of another applicationusing C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve

    Auto-entry of a password in a modal dialog box of another applicationusing C#

    Hi guys,

    You know how annoying it is when Visual Studio keeps asking you for a
    username and password to access TFS? I figured it would be easy to
    write a little System Tray utility that could use SendKeys to enter
    the username and password into the dialog box and click the OK button.
    (I ultimately plan on making the application generic so that it'll
    work with any application that requires information to be entered in a
    dialog box.)

    I figured wrong! Actually sending keys to an application using
    SendKeys is very easy. (There's a SendKeys class in the Diagnositcs
    namespace.) The hard part is making sure the correct window has focus,
    since the password window shown by Visual Studio is a modal dialog box
    within the devenv.exe process.

    So, the question is, does anyone know how to set focus to a modal
    dialog box of an another application from a C# application? I've tried
    enumerating through the Process to get the window, and I've tried
    using varios API calls (ShowWindow, FindWindowEx, etc...) but nothing
    has worked thus far.

    I'd be most grateful for any suggestions.

    Thanks in advance,

    Steve.

  • Chris Dunaway

    #2
    Re: Auto-entry of a password in a modal dialog box of anotherapplicat ion using C#

    On Apr 23, 9:42 am, Steve <stephen.bar... @atosorigin.com wrote:
    Hi guys,
    >
    You know how annoying it is when Visual Studio keeps asking you for a
    username and password to access TFS? I figured it would be easy to
    write a little System Tray utility that could use SendKeys to enter
    the username and password into the dialog box and click the OK button.
    (I ultimately plan on making the application generic so that it'll
    work with any application that requires information to be entered in a
    dialog box.)
    >
    I figured wrong! Actually sending keys to an application using
    SendKeys is very easy. (There's a SendKeys class in the Diagnositcs
    namespace.) The hard part is making sure the correct window has focus,
    since the password window shown by Visual Studio is a modal dialog box
    within the devenv.exe process.
    >
    So, the question is, does anyone know how to set focus to a modal
    dialog box of an another application from a C# application? I've tried
    enumerating through the Process to get the window, and I've tried
    using varios API calls (ShowWindow, FindWindowEx, etc...) but nothing
    has worked thus far.
    >
    I'd be most grateful for any suggestions.
    >
    Thanks in advance,
    >
    Steve.
    You might start by using Spy++ to see what the window handle is and
    the window name. That might help you figure out what to pass into
    EnumWindows or FindWindows.

    Chris

    Comment

    • Steve

      #3
      Re: Auto-entry of a password in a modal dialog box of anotherapplicat ion using C#

      On 23 Apr, 18:27, Chris Dunaway <dunaw...@gmail .comwrote:
      On Apr 23, 9:42 am, Steve <stephen.bar... @atosorigin.com wrote:
      >
      >
      >
      >
      >
      Hi guys,
      >
      You know how annoying it is when Visual Studio keeps asking you for a
      username and password to access TFS? I figured it would be easy to
      write a little System Tray utility that could use SendKeys to enter
      the username and password into the dialog box and click the OK button.
      (I ultimately plan on making the application generic so that it'll
      work with any application that requires information to be entered in a
      dialog box.)
      >
      I figured wrong! Actually sending keys to an application using
      SendKeys is very easy. (There's a SendKeys class in the Diagnositcs
      namespace.) The hard part is making sure the correct window has focus,
      since the password window shown by Visual Studio is a modal dialog box
      within the devenv.exe process.
      >
      So, the question is, does anyone know how to set focus to a modal
      dialog box of an another application from a C# application? I've tried
      enumerating through the Process to get the window, and I've tried
      using varios API calls (ShowWindow, FindWindowEx, etc...) but nothing
      has worked thus far.
      >
      I'd be most grateful for any suggestions.
      >
      Thanks in advance,
      >
      Steve.
      >
      You might start by using Spy++ to see what the window handle is and
      the window name.  That might help you figure out what to pass into
      EnumWindows or FindWindows.
      >
      Chris- Hide quoted text -
      >
      - Show quoted text -
      Hi Chris,

      Thanks for the advice! I tried that, but could not find a way to hook
      into the window using the information from Spy++. I'm sure I'm missing
      something really stupid...?

      If anyone wants to try and crack this challenge, you can get a dialog
      box easily by starting a new VSTS, connecting it to TFS and viewing a
      report. Then you get a dialog box on to enter details into.

      Cheers,

      Steve.

      Comment

      • john gold

        #4
        Re: Auto-entry of a password in a modal dialog box of another application using C#

        john@devdex.com



        *** Sent via Developersdex http://www.developersdex.com ***

        Comment

        • Toe Jam

          #5
          Re: Auto-entry of a password in a modal dialog box of another application using C#

          You can do this in .NET, but it is * much * easier in an automation tool
          like AutoIt (http://www.autoitscript.com/autoit3/). AutoIt has a
          function to activate a window by its Title, and then to send keystrokes
          or mouse movements. Here is some example code:

          ' WinExists checks for the existence of a window
          If WinExists("Micr osoft Visual Studio") Then

          ' WinActivate brings a window to the front
          ' and sets focus on it
          WinActivate("Mi crosoft Visual Studio")

          ' Send sends the keystrokes to current focus
          Send("myUserid{ TAB}myPassword{ ENTER}")
          EndIf




          *** Sent via Developersdex http://www.developersdex.com ***

          Comment

          Working...