Ok, so this is based on: Working example of CreateJobObject/SetInformationJobObject pinvoke in .net?
I have created a job object and attached it to an instance of MS Word. The job object has the UI Restriction WriteClipboard. My assumption was that this should prevent people from copying from the document. But that they could still paste into it. However, with only this restriction I am prevented from doing both.
I know the Job Object has been applied as it appears correctly in the tab in process explorer after the AssignProcessToJobObject completes.
I would have thought this to be the behaviour if I had specified a LIMIT Read & Write clipboard ui restriction.
Here is the constructor from the link above - ihave added the UIRestriction - Write Clipbard
public Job(string jobName)
{
handle = CreateJobObject(IntPtr.Zero, jobName);
var info = new JOBOBJECT_BASIC_LIMIT_INFORMATION
{
LimitFlags = 0x2000
};
var extendedInfo = new JOBOBJECT_EXTENDED_LIMIT_INFORMATION
{
BasicLimitInformation = info
};
int length = Marshal.SizeOf(typeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION));
IntPtr extendedInfoPtr = Marshal.AllocHGlobal(length);
Marshal.StructureToPtr(extendedInfo, extendedInfoPtr, false);
if (!SetInformationJobObject(handle, JobObjectInfoType.ExtendedLimitInformation, extendedInfoPtr, (uint)length))
throw new Exception(string.Format("Unable to set information. Error: {0}", Marshal.GetLastWin32Error()));
///UIRestrictions
var uiRestrictions = new JOBOBJECT_BASIC_UI_RESTRICTIONS
{
UIRestrictionsClass = 0x00000004 //No write to clipboard
};
length = Marshal.SizeOf(typeof(JOBOBJECT_BASIC_UI_RESTRICTIONS));
IntPtr basicUIInfoPtr = Marshal.AllocHGlobal(length);
Marshal.StructureToPtr(uiRestrictions, basicUIInfoPtr, false);
if (!SetInformationJobObject(handle, JobObjectInfoType.BasicUIRestrictions, basicUIInfoPtr, (uint)length))
throw new Exception(string.Format("Unable to set information. Error: {0}", Marshal.GetLastWin32Error()));
}
Then in the main program I do the following:
Job j = new Job("NewJob");
j.AddProcess(ProcID);
Where ProcID is the id of the process that I want to add the job to. I do check to see if the process already has a job before attempting to add one. Other than that I dont get any unusual errors and as I say the SysInternalstool, process explorer has the new job attached to the process.
Any ideas out there?