Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / Extensibility / November 2004

Tip: Looking for answers? Try searching our database.

Can not detach from a process

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Shai - 23 Nov 2004 21:33 GMT
I’m trying to have small add-in to attach to process (for example
winword.exe) and then detach from the process (without terminate the process).
The problem is I’m able to attach but can’t detach. What is the right way to
do this?

TIA
Shai

Enclosed the method I implemented on the default add-in wizard.

I added  class field as :
bool dettach = false;

and implemented this code in the exec method :

public void Exec(string commandName, EnvDTE.vsCommandExecOption
executeOption, ref object varIn, ref object varOut, ref bool handled)
        {
            try
            {
                handled = false;
                if(executeOption ==
EnvDTE.vsCommandExecOption.vsCommandExecOptionDoDefault)
                {
                    if(commandName == "MyAddinAttachProcess.Connect.MyAddinAttachProcess")
                    {
                        handled = true;
                        for (int i=1; i <= applicationObject.Debugger.LocalProcesses.Count;
i++)
                        {
                            EnvDTE.Process p = applicationObject.Debugger.LocalProcesses.Item(i);
                                if(Path.GetFileName(p.Name).ToLower() == "winword.exe")
                                {
                                    if(dettach)
                                    {
                                        p.Detach(false);
                                        //applicationObject.Debugger.DetachAll();
                                        MessageBox.Show("The proccess" + p.Name + " #" + p.ProcessID + "
was dettached.  " + applicationObject.Debugger.CurrentMode);
                                    }
                                    else
                                    {
                                        p.Attach();
                                        MessageBox.Show("The proccess" + p.Name + " #" + p.ProcessID + "
was attached. " + applicationObject.Debugger.CurrentMode  );

                                    }

                                dettach = !dettach;
                                break;
                            }
                        }
                        return;
                    }
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Addin");
            }
        }




Gary Chang[MSFT] - 24 Nov 2004 09:41 GMT
Hi Shai,

> ... What is the right way to  do this?

Your code is alright, however I am afraid you are unable to detach a
debugee process in a COM Interop mode even if you can detach it in the
debugger of the VS.NET IDE at the same time.

The reason is that it is impossible to detach the debugger from a process
if you specify more than one project type (e.g. Common Language Runtime and
Native) when the debugger attach to the process, and unfortunately when you
detach a debugee process
in COM Interop mode and in the current Object model there is no way to
specifiy which projects to attach.

You can also refer to the following google thread link which has a related
discussion on it:
http://groups.google.com/groups?hl=en&lr=&newwindow=1&c2coff=1&threadm=%23jj
orM%23uCHA.2424%40TK2MSFTNGP10&rnum=2&prev=/groups%3Fq%3Ddebugger%2520Detach
%2520Process%26hl%3Den%26lr%3D%26newwindow%3D1%26c2coff%3D1%26sa%3DN%26tab%3
Dwg

Thanks for your understanding!

Best regards,

Gary Chang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
Shai - 24 Nov 2004 22:49 GMT
Hi Gary !
Thanks for your answer.

Is there any other way, maybe via C++ ( Unmanaged ) Or Visual Studio .NET
Debugging SDK , to be able to detach from a process in VSIP package ?

> Hi Shai,
>
[quoted text clipped - 28 lines]
> This posting is provided "AS IS" with no warranties, and confers no rights.
> --------------------
Gary Chang[MSFT] - 25 Nov 2004 07:30 GMT
Hi Shai,

> Is there any other way, maybe via C++ ( Unmanaged ) Or Visual Studio .NET
> Debugging SDK , to be able to detach from a process in VSIP package ?

The platform SDK has an API DebugActiveProcessStop to detach the debugger
from a process, however it needs Windows XP or Windows 2003, and I think it
maybe difficult to use in a VSIP package:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/
debugactiveprocessstop.asp

By the way, one practical solution is hide the UI of your Add-in(if it
exists), and  be silent with any debug events until the  
EXIT_PROCESS_DEBUG_EVENT coming in the end...

Thanks for your understanding!

Best regards,

Gary Chang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.