Click here to Skip to main content
15,891,204 members
Articles / Programming Languages / C++

VS: Attach to Remote Process with AutoIt

Rate me:
Please Sign up or sign in to vote.
4.25/5 (3 votes)
6 Nov 2007Public Domain 28.4K   253   15  
Just a tiny tool to fix what was annoying me from VS 6

Introduction

This is just a tiny tool that fixes the problem that was annoying me since Visual Studio 6. Attaching to remote process was always annoying with all the unnecessary clicking.

Background

This script:

  • waits for VC++ to become active process
  • sends 'alt+d' and 'p' key sequence to open Processes dialog
  • sets Transport to TCP/IP
  • sets Name to host specified via command line parameter
  • waits for "Available Processes" list to be filled
  • searches for process name specified via command line parameter
  • clicks "Attach..." button
  • waits for "Debugged Processes" to be filled
  • clicks "Close" button

This was done after 2 hours (including this text) of playing with AutoIt (http://www.autoitscript.com/autoit3), I didn't use basic for years so please spare me if something could be done more optimised / whatever. It won't run without autoit.

I could have done it in C++, but it was quicker this way.

Using the Code

Code was written and tested on VC++ 2003, please change window parameters, it's trivial. Run the script without parameters, you will get msgbox.
Suggested use: Add it to external tools and create button in toolbar for quick access.

C++
if 3 <> UBound($CmdLine) Then
MsgBox(0, "Wrong parameters...", "attach.au host process>")
Exit(1)
EndIf

$computer = $CmdLine[1]
$process = $CmdLine[2]
$timeout = 10000

if 0 = WinWaitActive("[CLASS:wndclass_desked_gsk]", "MenuBar", $timeout) then
MsgBox(0, "Error.", "Cand find Visual Studio menu")
Exit(1)
EndIf

Send("{ALT}d")
Sleep(250)
Send("p")

if 0 = WinWaitActive("Processes", "", $timeout) then
MsgBox(0, "Error.", "Cand open Processes dialog")
Exit(1)
EndIf

ControlCommand("", "", 'ComboBox1', 'SetCurrentSelection', 'TCP/IP (Native only)')
ControlSetText("", "", "Edit1", $computer)
ControlClick("", "&Refresh", "Button6")

$item_count = ControlListView("", "List1", "SysListView321", "GetItemCount");
While 0 = $item_count
Sleep(250)
$item_count = ControlListView("", "List1", "SysListView321", "GetItemCount");
WEnd

Sleep(500)

$index_proc = ControlListView("", "List1", "SysListView321", "FindItem", $process, 0)
if $index_proc = -1 then 
MsgBox(0, "Process not found!", $process)
Exit(1)
Else
ControlListView("", "List1", "SysListView321", "DeSelect", 0, ControlListView
	("", "List1", "SysListView321", "GetItemCount"))
ControlListView("", "List1", "SysListView321", "Select", $index_proc)
ControlClick("", "&Attach...", "Button5")

While 0 = ControlListView("", "List2", "SysListView322", "GetItemCount")
Sleep(250)
WEnd

ControlClick("", "&Close", "Button11")
EndIf

Exit(0)

History

  • 6th November, 2007: Initial post

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication


Written By
Slovenia Slovenia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --