Esempio n. 1
0
        /// <summary>
        /// Creates a job object with the provided name, or opens one if it already exists.
        /// </summary>
        /// <param name="tracer">A tracer instance.</param>
        /// <param name="jobObjectName">The name of the job object, or null if it should be unnamed</param>
        /// <returns>The handle to the new (or reused) job object</returns>
        public static JobObject CreateOrOpenJobObject(ITracer tracer, string jobObjectName)
        {
            tracer.Trace(nameof(JobObject), "Creating job object '{0}'", jobObjectName);
            IntPtr unsafeJobObjectHandle = Methods.CreateJobObject(null /* lpJobAttributes */, jobObjectName);
            if (unsafeJobObjectHandle == IntPtr.Zero)
            {
                throw
                    new SandboxException(
                        $"Unable to create or open job object '{jobObjectName}'",
                        new Win32Exception());
            }

            var jobObject = new JobObject(tracer, unsafeJobObjectHandle, true /* ownsHandle */);

            try
            {
                jobObject.SetLimits();
                jobObject.SetUiRestrictions();
            }
            catch
            {
                jobObject.Dispose();
                throw;
            }

            return jobObject;
        }
 public JobObjectProtection(ITracer tracer)
 {
     this.JobObject = JobObject.CreateOrOpenJobObject(tracer, jobObjectName: null);
 }