16

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?

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
1800 INFORMATION
  • 131,367
  • 29
  • 160
  • 239
  • The job object that your process is in is the one visual studio is in. I don't know how or if visual studio can be configured to spawn your process with the CREATE _ BREAKAWAY _ FROM _ JOB flag. – sphereinabox Sep 18 '08 at 05:56
  • Why do you need that and why isn't it appropriate for the program itself to detect when it is not running in the right "job" and break away itself? – David Schmitt Sep 18 '08 at 10:05
  • 4
    You can't break away from a job once the process is already started – 1800 INFORMATION Sep 18 '08 at 19:29
  • We had the same behavior with a previous version of Visual Studio. At least in VS 2017 the process is not part of a job anymore. IsProcessInJob reports now FALSE. – BOFHRAF Mar 12 '19 at 18:34

3 Answers3

25

This happens when devenv.exe or VSLauncher.exe run 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.

You can globally disable PCA using Run -> gpedit.msc -> Administrative Templates\Windows Components\Application Compatibility -> Turn off Program Compatibility Assistant -> 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.exe and VSLauncher.exe, on separate lines and without quotes. For me, these were:

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.

skolima
  • 31,963
  • 27
  • 115
  • 151
Tom Minka
  • 794
  • 6
  • 10
  • Thanks, this sounds very interesting. Obviously I am not suffering this issue anymore but in case anyone else is this could help them. – 1800 INFORMATION Dec 15 '10 at 22:52
1

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:

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...).

mdb
  • 52,000
  • 11
  • 64
  • 62
  • In the debugging options for the project there is a "Attach to process" option which will make debugging a little more seamless. [Either way, this doesn't work very well if the process [say a command-line utlity] is non-interactive and finishes before you can attach to it... #ifdef DEBUG FTW!] – sphereinabox Sep 18 '08 at 19:49
  • It doesn't really matter, actually the problem occurs whether the process is started in the debugger or not, so long as it is started from visual studio. Thanks for the suggestion though. – 1800 INFORMATION Sep 18 '08 at 19:59
1

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.

Are you sure the debugger is doing this?

Peter Ritchie
  • 35,463
  • 9
  • 80
  • 98
  • No doubt about it. I can see in Process Explorer that it is started inside a job that contains devenv. If I start it from the command line then it is inside no job when it starts. – 1800 INFORMATION Sep 18 '08 at 19:31