views:

461

answers:

3

I want to launch a process in suspended state. Is there any way to do this by using only standard tools coming with Windows XP? Is there any lightweight third party tools?

Problem I'm trying to solve:
I have a application which I want to debug it by using Visual Studio 2005. I have debug build with necessary *.pdb files and I have all sources referenced from these *.pdb files. I don't want to create an empty solution which will run that application for me, so I'm trying to attach to this process after it's launched from other place. Some part of code I want to debug is executed at the beginning of process start-up, so I want to run it in suspended mode, attach a debugger and then resume it.

+2  A: 

You can easily write an application which will do it for you. Use the CreateProcess() function, set CREATE_SUSPENDED flag in the dwCreationFlags parameters.

For your specific task the application could do the following: call CreateProcess() to start the application and check the error code, then call MessageBox() to tell you to attach the debugger, then after you've pressed a button on the message box (MessageBox() returns) call ResumeThread() to resume the application.

sharptooth
I know I can, but I think it's better to use standard tools (if any).
Dmitriy Matveev
+3  A: 

I'm not exactly sure what you're trying to do from your question, but maybe using the ntsd debugger which comes with XP will help you do what you want (by default, ntsd will load the process and stop at the first instruction).


From the updated information in your question, I'd suggest downloading the Debugging Tools for Windows package from Microsoft and debugging the startup stuff in WinDbg -the are some things that Visual Studio is better at, but there are also some things that WinDbg is better at than Visual Studio (WinDBg is a very powerful debugger).

Or you can simply load the program in the Visual Studio debugger (without a solution) from the command line:

devenv /debugexe yourprog.exe <arguments>
Michael Burr
A: 

Regarding lightweight 3rd party tools:

Sysinternals Processor Explorer:
http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx

. . . allows you to Suspend and Resume proceses. It can't "launch" them suspended, but may be useful to your purpose anyway. It's a free download.

William Leara
Currently I'm using it for suspending debugged application early, but this isn't what I want.
Dmitriy Matveev