IsProcessInJob (kernel32)
Last changed: -194.190.17.173

.
Summary
TODO - a short description

C# Signature:

[DllImport ("kernel32.dll")]

public static extern bool IsProcessInJob (IntPtr Process, IntPtr Job, out bool Result);

VB Signature:

User-Defined Types:

Alternative Managed API:

None!!!

Notes:

Tips & Tricks:

English:

Process - A handle to the process to be tested. The handle must have the PROCESS_QUERY_INFORMATION access right.

Job - A handle to the job. If this parameter is NULL, the function tests if the process is running under any job.If this parameter is not NULL, the handle must have the JOB_OBJECT_QUERY access right.

Result - A pointer to a value that receives TRUE if the process is running in the job, and FALSE otherwise.

Return Value - If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError.

Russian:

Process - дескриптор процесса, должен иметь доступ PROCESS_QUERY_INFORMATION

Job - дескриптор задания, должен иметь доступ JOB_OBJECT_QUERY, если он IntPtr.Zero то проверяется, находится ли процесс в каком-либо задании.

Result - если true - процесс в задании, false - не в задании

Return Value - если все успешно - true, если ошибка - false.

Sample Code:

[StructLayout(LayoutKind.Sequential)]

public class SecurityAttributes

{

  public int nLength; //Useless field = 0
  public IntPtr pSecurityDescriptor; //хз))
  public bool bInheritHandle; //Возможность наследования

  public SecurityAttributes ()
  {
     this.bInheritHandle = true;
     this.nLength = 0;
     this.pSecurityDescriptor = IntPtr.Zero;
  }
}

[DllImport("kernel32.dll")]

public static extern IntPtr GetCurrentProcess();

[DllImport("kernel32.dll")]

public static extern bool CloseHandle(IntPtr Object);

[DllImport("kernel32.dll",EntryPoint="CreateJobObjectW", CharSet=CharSet.Unicode)]

public static extern IntPtr CreateJobObject(SecurityAttributes JobAttributes, string lpName);

[DllImport("kernel32.dll")]

public static extern bool AssignProcessToJobObject(IntPtr Job, IntPtr Process);

[DllImport ("kernel32.dll")]

public static extern bool IsProcessInJob (IntPtr Process, IntPtr Job, out bool Result);

public static void Main ()

{

  bool Is;
  IntPtr Job = CreateJobObject (null, "Хуй =)");
  AssignProcessToJobObject(Job, GetCurrentProcess());

  IsProcessInJob (GetCurrentProcess (), Job, out Is);
  Console.WriteLine ("That process in that job: " + Is);

  IsProcessInJob (GetCurrentProcess (), IntPtr.Zero, out Is);
  Console.WriteLine ("That process in any job: " + Is);

  CloseHandle (Job);
  Console.ReadKey();

}

Documentation