windows 有没有办法在暂停状态下启动进程?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/963725/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there any way to start process in suspended state?
提问by okutane
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?
我想启动一个处于挂起状态的进程。有没有办法只使用 Windows XP 附带的标准工具来做到这一点?有没有轻量级的第三方工具?
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.
我正在尝试解决的问题:
我有一个应用程序,我想使用 Visual Studio 2005 对其进行调试。我使用必要的 *.pdb 文件进行调试构建,并且我拥有从这些 *.pdb 文件中引用的所有源。我不想创建一个空的解决方案来为我运行该应用程序,所以我试图在它从其他地方启动后附加到这个进程。我想调试的部分代码在进程启动开始时执行,所以我想在挂起模式下运行它,附加调试器然后恢复它。
采纳答案by Michael Burr
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).
我不确定你想从你的问题中做什么,但也许使用 XP 附带的 ntsd 调试器会帮助你做你想做的事(默认情况下,ntsd 将加载进程并在第一条指令处停止) .
From the updated information in your question, I'd suggest downloading the Debugging Tools for Windows packagefrom 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).
根据您问题中的更新信息,我建议从 Microsoft下载Windows 调试工具包并在 WinDbg 中调试启动内容 - 这些是 Visual Studio 更擅长的一些事情,但也有一些事情 WinDbg 更好在比 Visual Studio(WinDBg 是一个非常强大的调试器)。
Or you can simply load the program in the Visual Studio debugger (without a solution) from the command line:
或者您可以简单地从命令行在 Visual Studio 调试器中加载程序(没有解决方案):
devenv /debugexe yourprog.exe <arguments>
回答by sharptooth
You can easily write an application which will do it for you. Use the CreateProcess() function, set CREATE_SUSPENDED flag in the dwCreationFlags
parameters.
您可以轻松编写一个应用程序来为您完成。使用 CreateProcess() 函数,在dwCreationFlags
参数中设置 CREATE_SUSPENDED 标志。
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.
对于您的特定任务,应用程序可以执行以下操作:调用 CreateProcess() 启动应用程序并检查错误代码,然后调用 MessageBox() 告诉您附加调试器,然后在您按下消息框上的按钮后(MessageBox() 返回)调用 ResumeThread() 来恢复应用程序。
回答by HairOfTheDog
I've been asking myself this same question for a while now and just now found this pretty neat little tool that will do exactly what you (and I) want. You can get just the binary, or the source too.
一段时间以来,我一直在问自己同样的问题,现在才发现这个非常简洁的小工具可以完全满足您(和我)的要求。您可以只获取二进制文件,也可以获取源代码。
http://www.codeproject.com/Articles/230005/Launch-a-process-suspended
http://www.codeproject.com/Articles/230005/Launch-a-process-suspended
回答by William Leara
Regarding lightweight 3rd party tools:
关于轻量级 3rd 方工具:
SysInternals Process Explorer:
http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx
SysInternals 进程资源管理器: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.
...允许您暂停和恢复进程。它不能“启动”它们暂停,但无论如何可能对您的目的有用。这是一个免费下载。