0

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?

Community
  • 1
  • 1
BinaryX
  • 1
  • 2
  • How are setting the restriction on the job object? – Peter Ritchie Jul 21 '12 at 00:46
  • Hi Peter, I have edited the original question to show the code that I am using. NOte that it is based on the link given. – BinaryX Jul 21 '12 at 07:53
  • Looks to me like you're setting the write clipboard restriction properly. What do you mean by "prevented by doing both"? Do you get an error, nothing happens, etc? How are you getting data into the clipboard to paste? Can it be pasted in another app not part of this job? – Peter Ritchie Jul 21 '12 at 15:41
  • Ok, so I set the Job on MS Word. The I select text in the window, copy and attempt to paste into say, Notepad. Notepad does not have a Job on it. Nothing is pasted, this is expected. What isn't expected is when I select text in notepad and attempt to paste it into MS Word. Since I have only set Limit Write Clipboard for MS Word I would expect the text to paste into MSWord just fine. It doesn't. By setting the write clipboard option on MSWord i seem to have disabled clipboard reading as well. When I attempt to paste into MSWord (i.e. trigger a clipboard read) nothing happens. No error at all. – BinaryX Jul 21 '12 at 15:58
  • If this doesn't work then I will be forced to use API hooks to hook USer32.dd's SetClipboardData function. I'm loath to do this when the Job object should perform this function for me in the proper way. – BinaryX Jul 21 '12 at 16:00
  • Hmm, the only thing I can think of is that Word is trying to write the clipboard when it pastes. Can you put the same restriction on a notepad instance and get it to work as you expected? That would tell you if the issue is with how Word using the clipboard or with this code. – Peter Ritchie Jul 21 '12 at 16:03
  • Yeah, I tried that. I loaded up an instance of notepad - got the process id and added the job UI restriction to it (verified in process explorer). Then I opened a second instance of notepad. Again two-way copy and paste is blocked - when I have only asked for Write Prevent on the JobObject process. Weird. My use case is simple. Once the process is added to the job i want to restrict copying sensitive data to the clipboard. – BinaryX Jul 21 '12 at 16:12

0 Answers0