OleClipboard and IDataObject under local SYSTEM account

joeyes 30 Reputation points
2023-02-07T16:56:48.93+00:00

There is an implementation of remote file transfer via dragging virtual files using IStream/IDataObject (based on Raymond Chen's blog topic: What a drag: Dragging a virtual file (IStream edition)).

Basically, it works good. But if the application is run under the SYSTEM account, the IDataObject::GetData() is called only once - requests a FILEDESCRIPTOR, but doesn't return with a requests for FILECONTENTS.

How I use IDataObject:


if (SUCCEEDED(OleInitialize(NULL))) {
    IDataObject* dtob = new MyDataObject(/*some files info here*/);
    if (dtob) {
        OleSetClipboard(dtob);
        dtob->Release();
    }
    
    //simulate Ctrl-V
    ...
    
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    OleUninitialize();
}
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,413 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,513 questions
{count} votes

Accepted answer
  1. Sam Barraclough 85 Reputation points
    2023-02-14T20:06:14.3066667+00:00

    It sounds like we're working on similar projects - software KVM with clipboard functions.

    After a very long time, I figured out that the reason it doesn't work on the SYSTEM account is because of COM security. I managed to get it working by using the CoInitializeSecurity function:

    Ole32.CoInitializeSecurity(
                0,
                0,
                default,
                0,
                Rpc.RPC_C_AUTHN_LEVEL.RPC_C_AUTHN_LEVEL_NONE,
                Rpc.RPC_C_IMP_LEVEL.RPC_C_IMP_LEVEL_IDENTIFY,
                default,
                default,
                default).ThrowIfFailed();
    
    2 people found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. RLWA32 39,916 Reputation points
    2023-02-08T10:36:08.55+00:00

    There is a security boundary for the clipboard between elevated processes running as SYSTEM and non-elevated processes for certain clipboard formats. This boundary is not documented to the best of my knowledge. You will find that if you place simple text on the clipboard from an elevated process running as SYSTEM that it can be pasted into Notepad.


  2. Xiaopo Yang - MSFT 11,251 Reputation points Microsoft Vendor
    2023-02-10T02:32:06.85+00:00

    Hello @joeyes The code also works fine for me.

    User's image

    User's image