visual-studio 如何停止 Visual Studio 调试器在作业对象中启动我的进程?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/89791/
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
How to stop the Visual Studio debugger starting my process in a job object?
提问by 1800 INFORMATION
When I start my process from Visual Studio, it is always created inside a job object. I would like to know how to turn this behaviour off. Any ideas?
当我从 Visual Studio 启动我的流程时,它总是在作业对象中创建。我想知道如何关闭这种行为。有任何想法吗?
I expect that it is created in a job object to be debugged. I want to place my program in a different job object.
我希望它是在要调试的作业对象中创建的。我想将我的程序放在不同的作业对象中。
It's not the hosting process. I'm talking about a Job Object. This is an unmanaged C++ application.
这不是托管过程。我说的是Job Object。这是一个非托管的 C++ 应用程序。
回答by Tom Minka
This happens when devenv.exeor VSLauncher.exerun in compatibility mode. The Program Compatibility Assistant(PCA) attaches a job object to the Visual Studio process, and every child process inherits it. Check if the job name (as reported by Process Explorer) starts with PCA. If so, PCA can be disabled as described in the link.
当devenv.exe或VSLauncher.exe在兼容模式下运行时会发生这种情况。该程序兼容性助手(PCA)附加一个作业对象到Visual Studio的过程,每个子进程将继承它。检查作业名称(由 Process Explorer 报告)是否以PCA开头。如果是这样,可以按照链接中的说明禁用 PCA。
You can globally disable PCA using Run-> gpedit.msc-> Administrative Templates\Windows Components\Application Compatibility-> Turn off Program Compatibility Assistant-> Enable.
您可以使用Run-> gpedit.msc-> Administrative Templates\Windows Components\Application Compatibility-> Turn off Program Compatibility Assistant->全局禁用 PCA Enable。
You can disable PCA for specific executables by adding a registry entry. For Windows 7, the appropriate registry key is HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant. In regedit, right-click that key, select New-> Multi-String Value, name it ExecutablesToExclude. Set the value to the full path of denenv.exeand VSLauncher.exe, on separate lines and without quotes. For me, these were:
您可以通过添加注册表项来禁用特定可执行文件的 PCA。对于 Windows 7,适当的注册表项是HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant. 在 regedit 中,右键单击该键,选择New-> Multi-String Value,将其命名为ExecutablesToExclude。将该值设置为的完整路径denenv.exe和VSLauncher.exe,在不同的线条和不带引号。对我来说,这些是:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe
C:\Program Files (x86)\Common Files\microsoft shared\MSEnv\VSLauncher.exe
A related issue, on Windows 7, is that executables you build in Visual Studio and run from Explorer (not Visual Studio or the command line) may run in compatibility mode, and again get job objects wrapped around them. To prevent this, your executable needs a manifest that declares compatibility with Windows 7, using the new Application Manifest Compability section. The link gives an example of a Windows 7 compatible manifest. The default manifest provided by Visual Studio 2010 does not include this Compatibility section.
在 Windows 7 上,一个相关的问题是,您在 Visual Studio 中构建并从资源管理器(而不是 Visual Studio 或命令行)运行的可执行文件可能会在兼容模式下运行,并再次将作业对象包裹在它们周围。为防止出现这种情况,您的可执行文件需要使用新的应用程序清单兼容性部分声明与 Windows 7 兼容的清单。该链接提供了 Windows 7 兼容清单的示例。Visual Studio 2010 提供的默认清单不包括此兼容性部分。
回答by mdb
I'm not aware of any ways to control this aspect of processes spawned for debugging by VS.NET. But there's a workaround, which is applicable to any situation in which VS.NET can't or doesn't start your process in the exact way you want:
我不知道有什么方法可以控制 VS.NET 为调试而生成的进程的这一方面。但是有一个解决方法,它适用于 VS.NET 不能或不以您想要的确切方式启动您的进程的任何情况:
Start your process (possibly using a wrapper EXE that runs as part of the post-build event), then attach to the newly started process using Tools/Attach to Process. If you break into the debugger as part of your startup code, this won't even be required (and you can also debug startup issues...).
启动您的进程(可能使用作为构建后事件的一部分运行的包装器 EXE),然后使用工具/附加到进程附加到新启动的进程。如果作为启动代码的一部分闯入调试器,则甚至不需要这样做(并且您还可以调试启动问题......)。
回答by Peter Ritchie
I can't reproduce what you're seeing. I've created an unmanaged C++ application in both VS 2005 and VS 2008 and I have no problems associating that process to a new job object when starting the process in VS.
我无法重现你所看到的。我已经在 VS 2005 和 VS 2008 中创建了一个非托管 C++ 应用程序,并且在 VS 中启动进程时,我没有问题将该进程关联到一个新的作业对象。
Are you sure the debugger is doing this?
您确定调试器正在执行此操作吗?

