Skip to content

Open file with zero access mode read permissions in file-id crate #625

@mhnap

Description

@mhnap

As an improvement to the file-id crate, I would propose change:

.read(true)

to:

.access_mode(0)

From https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea#files:

The dwDesiredAccess parameter can be zero, allowing the application to query file attributes without accessing the file if the application is running with adequate security settings. This is useful to test for the existence of a file without opening it for read and/or write access, or to obtain other statistics about the file or directory.

For example, currently, I get an error trying to get info for C:\Users\Administrator\AppData\Local\Microsoft\Windows\UsrClass.dat file:

Os {
    code: 32,
    kind: Uncategorized,
    message: "The process cannot access the file because it is being used by another process.",
},

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions