Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

ProcThreadAttributeJobListDotNet

A managed wrapper around PROC_THREAD_ATTRIBUTE_JOB_LIST.

Warning

This class library only works on Windows 10 and newer, or Windows Server 2016 and newer. If you need a solution for Linux or macOS, there is a discussion here.

License

ProcThreadAttributeJobListDotNet is licensed under The MIT License.

Getting Started

Install the ProcThreadAttributeJobListDotNet package from NuGet.

Atomically Create Process In Job

var extendedLimitInformation = new JobObjectExtendedLimitInformation
{
    BasicLimitInformation = { LimitFlags = JobObjectLimit.KillOnJobClose }
};

using var safeJobObjectHandle = extendedLimitInformation.CreateJobObject();

using var process = safeJobObjectHandle.CreateAssociatedProcess(
    @"C:\Windows\System32\notepad.exe", @"C:\Windows\System32\drivers\etc\hosts");

// ...

Configure StartupInfo

CreateAssociatedProcess necessarily creates StartupInfoEx for its AttributeList. The contents of the concomitant StartupInfo (except for cb) are irrelevant to creating an associated process, so you can use configureStartupInfo to control the created process further:

var extendedLimitInformation = new JobObjectExtendedLimitInformation
{
    BasicLimitInformation = { LimitFlags = JobObjectLimit.KillOnJobClose }
};

using var safeJobObjectHandle = extendedLimitInformation.CreateJobObject();

using var process = safeJobObjectHandle.CreateAssociatedProcess(
    @"C:\Windows\System32\notepad.exe", configureStartupInfo: MyConfiguration);

// ...

void MyConfiguration(ref StartupInfo startupInfo)
{
    startupInfo.Flags = StartupInfoFlags.UseShowWindow;
    startupInfo.ShowWindowCommand = ShowWindowCommand.Maximize;
}

Acknowledgements

Raymond Chen for bringing PROC_THREAD_ATTRIBUTE_JOB_LIST to my attention in A more direct and mistake-free way of creating a process in a job object.

CsWin32 for generating several of the structures and enums required.

PInvoke.net for the rest.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages