Permissions needed for WriteProcessMemory appear to be inaccurately documented

RLWA32 52,946 Reputation points
2026-11-01T15:32:59.41+00:00

The documentation for the WriteProcessMemory function states that the process handle passed to the function "must have PROCESS_VM_WRITE and PROCESS_VM_OPERATION access to the process."

This appears to be inaccurate as a handle obtained without requesting PROCESS_VM_OPERATION (PROCESS_VM_WRITE | PROCESS_VM_READ | PROCESS_QUERY_LIMITED_INFORMATION was requested) access was sufficient to write to target process memory.

This was noticed when reviewing and testing code in one of Pavel Yosifovich's repositories at https://github.com/zodiacon/youtubecode/blob/main/HideDll/HideDll/HideDll.cpp

Windows development | Windows API - Win32

2 answers

Sort by: Oldest
  1. AI answer

    2026-11-01T15:34:01.4266667+00:00

    WriteProcessMemory callers should continue requesting both PROCESS_VM_WRITE and PROCESS_VM_OPERATION; success with only PROCESS_VM_WRITE is observable implementation behavior for some writable target pages, not the documented access contract.

    Why the tested call succeeds

    The public contract states that the handle must contain both rights:

    • PROCESS_VM_WRITE permits writing to process memory.
    • PROCESS_VM_OPERATION permits operations on the process address space and is explicitly associated with both VirtualProtectEx and WriteProcessMemory in the process-rights table.^1^
    • The WriteProcessMemory reference likewise requires both rights.^2^

    However, Microsoft has described WriteProcessMemory as conditionally changing page protection when the destination is read-only: it temporarily makes the page writable, writes the bytes, and restores the original protection. This debugger-oriented behavior requires the caller to be able to modify protection; otherwise that attempt fails.^3^ VirtualProtectEx itself requires PROCESS_VM_OPERATION.^4^

    That produces two relevant cases:

    1. The destination is already writable.
      The current Windows implementation may complete the copy using PROCESS_VM_WRITE without performing a protection operation. This is consistent with the observed result.
    2. The destination is not writable and WriteProcessMemory must adjust its protection.
      The operation needs the authority represented by PROCESS_VM_OPERATION; a handle lacking that right cannot rely on the write succeeding.

    The tested repository therefore demonstrates that PROCESS_VM_OPERATION is not necessarily checked on every successful execution path. It does not establish that the right can safely be omitted from code intended to satisfy the API contract across target pages or Windows versions.

    Use the documented minimum for production code:

    DWORD access =
        PROCESS_VM_WRITE |
        PROCESS_VM_OPERATION |
        PROCESS_QUERY_LIMITED_INFORMATION;
    
    HANDLE process = OpenProcess(access, FALSE, processId);
    if (!process) {
        // Handle GetLastError().
    }
    

    Add PROCESS_VM_READ only if the program also calls ReadProcessMemory; it is not part of the documented WriteProcessMemory requirement.^1^

    Is the documentation inaccurate?

    It is conservative rather than a precise description of every internal path. The text documents the supported permissions callers must obtain, while the implementation can avoid using PROCESS_VM_OPERATION when no address-space operation is necessary.

    A useful documentation clarification would be:

    Callers must request PROCESS_VM_WRITE and PROCESS_VM_OPERATION. Some implementations may successfully write to an already-writable region with only PROCESS_VM_WRITE, but applications must not rely on that behavior.

    This distinction can be submitted through Feedback → This page on the WriteProcessMemory documentation page, including:

    • the Windows build tested;
    • the exact OpenProcess access mask;
    • the target page’s protection;
    • a minimal reproducer showing success without PROCESS_VM_OPERATION;
    • whether the same test fails against a read-only target page.

    References

    1. Process Security and Access Rights - Win32 apps
    2. WriteProcessMemory function (memoryapi.h) - Win32 apps
    3. How is it that Write­Process­Memory succeeds in writing to read-only ...
    4. VirtualProtectEx function (memoryapi.h)
    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

  2. Nguyen Dam (WICLOUD CORPORATION) 1,175 Reputation points Microsoft External Staff Moderator
    2026-11-02T03:24:44.94+00:00

    Hello @RLWA32 and thank you for catching and bringing attention to this documentation issue. 

    I reproduced the behavior using WriteProcessMemory with a process handle that did not have PROCESS_VM_OPERATION, and the call still succeeded, as you observed. The GitHub code you linked provides another example where the operation succeeds without that flag.

    User's image

    Since the documented requirement does not appear to match the observed behavior, I suggest submitting feedback directly on the documentation page so the documentation team can clarify or correct it. Select the thumbs-down button next to Was this page helpful? You can then choose Other and describe your findings in the Tell us more box. 

    If you found my response helpful or informative, I would greatly appreciate it if you could follow this guide for your confirmation. Thank you. 

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.