Join our Newsletter — 33% off our NHI Course
Foundations & NHI Taxonomy

CreateFileW

← Back to Glossary
By NHI Mgmt Group Updated October 29, 2026 Domain: Foundations & NHI Taxonomy

CreateFileW is the Unicode Windows API function used to open or create a file, directory, device, or named pipe. It takes a path plus access flags, share mode, security attributes, creation disposition, and file attributes, then returns a handle that governs subsequent read, write, and delete operations.

What CreateFileW Does in Windows

CreateFileW is the Windows file system entry point that establishes the initial handle to a file, directory, device, or named pipe. That handle is the security-relevant object that later operations depend on, so the flags chosen at open time shape what the caller can do next.

Because it can target both ordinary files and other kernel-backed objects, CreateFileW is often less about “creating a file” in the narrow sense and more about requesting access through Windows object semantics. In practice, the call is where a process declares intent, desired access, sharing behaviour, and creation behaviour all at once.

Why CreateFileW Matters for Access Control

The parameters to CreateFileW are where access decisions become concrete. Desired access determines whether the caller wants to read, write, append, delete, or query metadata, while share mode and security attributes affect whether other processes can open the same object and under what protection context.

This makes the function central to Windows authorization behaviour even though it is not itself an access-control policy. A weak open request can overexpose data or lock out other software, while a restrictive request can fail in ways that look like an application bug but are really a permissions or sharing issue.

When the target is a named pipe or device, the same API can become part of interprocess communication or privileged subsystem access. That means the caller must be prepared for object type specific semantics, not just the generic idea of “open a file.”

Common Failure Modes and Security Consequences

Many CreateFileW problems come from assuming the path refers only to a normal file. Reparse points, device namespaces, directory handles, and pipe names can all shift the security meaning of the call and produce access to a different object than the developer intended.

Incorrect creation disposition is another common source of risk. Opening when the code expected to create, or creating when the code expected to open, can lead to overwrite, truncation, or logic flaws that expose sensitive content or break integrity assumptions.

Sharing flags also matter. If a process opens an object with overly permissive sharing, another actor may be able to interfere with reads, writes, or deletion. If it opens too restrictively, availability suffers because benign concurrent access is denied.

How to Use CreateFileW Safely in Practice

Use the narrowest access mask that satisfies the operation, and treat the handle as a privilege-bearing capability rather than a neutral reference. For sensitive paths, explicitly reason about whether the code needs read, write, delete, or metadata access, because each additional right expands the impact of handle misuse.

Validate the object type and path semantics before opening when the input is user-controlled or derived from another process. On Windows, that means thinking about directories, alternate namespaces, devices, and pipe endpoints as distinct security objects, not interchangeable strings.

When CreateFileW is used for privileged workflows, pair it with strong error handling and post-open checks so that the program does not silently continue with the wrong object or a weaker security outcome than intended.

Practitioner note: Many security bugs around CreateFileW are not “file bugs” at all, but object-resolution bugs. The security boundary is often the handle you receive, not the path you started with.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

NIST SP 800-53 Rev 5 and CIS Controls v8 set the technical controls, while ISO/IEC 27001:2022 defines the regulatory obligations.

FrameworkControl / ReferenceRelevance
NIST SP 800-53 Rev 5AC-6 — Least PrivilegeCreateFileW access flags directly determine requested rights on the object.
IA-2 — Identification and Authentication (Organizational Users)File and device opens rely on the authenticated identity behind the process token.
CM-7 — Least FunctionalityRestrict unnecessary object types and operations when code uses CreateFileW.
Recommendation — Request only the minimal access needed for each handle open. Ensure the caller's identity is properly authenticated before it opens sensitive objects. Limit software to the object types and access paths it actually needs.
CIS Controls v8CIS-6 — Access Control ManagementCreateFileW shapes effective access to local objects through permissions and sharing.
Recommendation — Review object access paths and remove unnecessary rights or sharing exposure.
ISO/IEC 27001:2022A.8.24 — Use of CryptographySensitive file opens often need cryptographic protection layered around the data they expose.
Recommendation — Protect sensitive data opened through the API with appropriate encryption controls.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Reviewed and updated by the NHIMG editorial team on October 29, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org