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

S

Steve

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.
 
C

Chris Dunaway

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
 
S

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.
 
T

Toe Jam

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("Microsoft Visual Studio") Then

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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top