SetInformationJobObject (kernel32)
Last changed: DMS-167.136.242.30

.
Summary

C# Signature:

[DllImport("kernel32.dll")]
static extern bool SetInformationJobObject(IntPtr hJob,
   JOBOBJECTINFOCLASS JobObjectInfoClass, IntPtr lpJobObjectInfo,
   uint cbJobObjectInfoLength);

VB Signature:

<DllImport("kernel32.dll", SetLastError:=True)> _
Private Shared Function SetInformationJobObject(hJob As IntPtr, JobObjectInfoClass As JOBOBJECTINFOCLASS, lpJobObjectInfo As IntPtr, cbJobObjectInfoLength As UInteger) As Boolean
End Function

User-Defined Types:

JOBOBJECTINFOCLASS

JOBOBJECT_BASIC_LIMIT_INFORMATION

JOBOBJECT_EXTENDED_LIMIT_INFORMATION

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

Please add some!

VB Sample Code:

Dim j_handle As IntPtr
'Create new Job
j_handle = CreateJobObject(Nothing, Nothing)
'Create job info structure
Dim info As New JOBOBJECT_BASIC_LIMIT_INFORMATION()
'Set process limit count to one
info.ActiveProcessLimit = &H1
'Set job info flags to activate process limiting
info.LimitFlags = &H8

'Get length of job limit structure
Dim length As Integer = Marshal.SizeOf(GetType(JOBOBJECT_BASIC_LIMIT_INFORMATION))
'Create a pointer to our structure
Dim basicInfoPtr As IntPtr = Marshal.AllocHGlobal(length)
Marshal.StructureToPtr(info, basicInfoPtr, False)

'Store the job information settings to the job object
Dim intreturn As Integer = SetInformationJobObject(j_handle, JOBOBJECTINFOCLASS.BasicLimitInformation, basicInfoPtr, CUInt(length))
If Not SetInformationJobObject(j_handle, JOBOBJECTINFOCLASS.BasicLimitInformation, basicInfoPtr, CUInt(length)) Then
   Throw New Exception(String.Format("Unable to set information.  Error: {0}", Marshal.GetLastWin32Error()))
End If

Alternative Managed API:

Do you know one? Please contribute it!

Documentation