os.windows.native_api

Windows Native API (NT) wrappers using ctypes.

Module Contents

Classes

FileAttribute

list of file attributes constants.

IOReparseTag

Reparse Point Tag constants.

Access

Desired Access constants.

Share

Share Access constants.

OpenOptions

File Open options.

Wait

Constants for WaitFor* functions.

Status

Error constants.

IOStatusBlock

Map IO_STATUS_BLOCK structure.

ReparseGUIDDataBuffer

Map Windows REPARSE_GUID_DATA_BUFFER structure.

UnicodeString

Map UNICODE_STRING structure.

FileTime

Map FILETIME structure.

LargeFileTime

Map filetime implemented using LARGE_INTEGER.

FindData

Map Windows WIN32_FIND_DATA structure.

FileInfo

Declaration of structures returned by QueryInformationFile.

ObjectInfo

Declaration of structures returned by QueryObjectInformation.

ProcessInfo

Declaration of structure returned by QueryInformationProcess.

ObjectAttributes

OBJECT_ATTRIBUTES structure.

NT

Container for Windows NT API function bindings.

Attributes

NTSTATUS

W32_EPOCH_OFFSET

NTException

os.windows.native_api.NTSTATUS
class os.windows.native_api.FileAttribute

Bases: ctypes.Structure

list of file attributes constants.

READONLY = 1
HIDDEN = 2
SYSTEM = 4
DIRECTORY = 16
ARCHIVE = 32
DEVICE = 64
NORMAL = 128
TEMPORARY = 256
SPARSE_FILE = 512
REPARSE_POINT = 1024
COMPRESSED = 2048
OFFLINE = 4096
NOT_CONTENT_INDEXED = 8192
ENCRYPTED = 16384
INTEGRITY_STREAM = 32768
VIRTUAL = 65536
NO_SCRUB_DATA = 131072
_fields_ = [('attr',)]
__str__() str

Return string representation of active file attributes.

class os.windows.native_api.IOReparseTag

Reparse Point Tag constants.

This is important to note that symbolic links on Windows are always implemented using reparse points. Nevertheless a reparse point is a more general concept not always associated with the concept of symbolic links. In the present code we are only interested in checking whether a reparse point is a symbolic link or not.

Currenly Windows supports two kinds of symbolic links. One for Win32 apps (SYMLINK) and one for WSL subsystem (WSL_SYMLINK). Note that Cygwin now uses the second one to implement symbolic links. Note that WSL symbolic links are not handled correctly by the Python runtime (for example os.path.islink will return False).

class os.windows.native_api.Access

Desired Access constants.

LIST_DIRECTORY = 1
READ_DATA = 1
ADD_FILE = 2
WRITE_DATA = 2
ADD_SUBDIR = 4
APPEND_DATA = 4
READ_EA = 8
WRITE_EA = 16
EXECUTE = 32
TRAVERSE = 32
DELETE_CHILD = 64
READ_ATTRS = 128
WRITE_ATTRS = 256
DELETE = 65536
SYNCHRONIZE = 1048576
PROCESS_QUERY_INFORMATION = 1024
class os.windows.native_api.Share

Share Access constants.

NOTHING = 0
READ = 1
WRITE = 2
DELETE = 4
ALL = 7
class os.windows.native_api.OpenOptions

File Open options.

BACKUP_INTENT = 16384
SYNCHRONOUS_IO_NON_ALERT = 32
DELETE_ON_CLOSE = 4096
OPEN_REPARSE_POINT = 2097152
class os.windows.native_api.Wait

Constants for WaitFor* functions.

OBJECT = 0
ABANDONED = 128
TIMEOUT = 258
FAILED = 4294967295
INFINITE = 4294967295
class os.windows.native_api.Status

Error constants.

ACCESS_DENIED = 3221225506
OBJECT_NAME_NOT_FOUND = 3221225524
OBJECT_PATH_NOT_FOUND = 3221225530
SHARING_VIOLATION = 3221225539
DELETE_PENDING = 3221225558
DIRECTORY_NOT_EMPTY = 3221225729
CANNOT_DELETE = 3221225761
NO_MORE_FILES = 2147483654
msgs: ClassVar[dict[int, str]]
class os.windows.native_api.IOStatusBlock

Bases: ctypes.Structure

Map IO_STATUS_BLOCK structure.

_fields_ = [('status',), ('information',)]
class os.windows.native_api.ReparseGUIDDataBuffer

Bases: ctypes.Structure

Map Windows REPARSE_GUID_DATA_BUFFER structure.

_fields_ = [('tag',), ('length',), ('reserved',), ('guid',), ('data',)]
class os.windows.native_api.UnicodeString(value: str | None = None, max_length: int = 0)

Bases: ctypes.Structure

Map UNICODE_STRING structure.

_fields_ = [('length',), ('maximum_length',), ('buffer',)]
__len__() int

Return the length of the Unicode string.

os.windows.native_api.W32_EPOCH_OFFSET = 11644473600
class os.windows.native_api.FileTime(t: datetime.datetime)

Bases: ctypes.Structure

Map FILETIME structure.

property filetime: int

Filetime.

property as_datetime: datetime.datetime

Convert to datetime object.

_fields_ = [('filetime_low',), ('filetime_high',)]
__str__() str

Return string representation of file time.

class os.windows.native_api.LargeFileTime(t: datetime.datetime)

Bases: ctypes.Structure

Map filetime implemented using LARGE_INTEGER.

property as_datetime: datetime.datetime

Convert to datetime object.

_fields_ = [('filetime',)]
__str__() str

Return string representation of large file time.

class os.windows.native_api.FindData

Bases: ctypes.Structure

Map Windows WIN32_FIND_DATA structure.

_fields_ = [('file_attributes',), ('creation_time',), ('last_access_time',), ('last_write_time',),...
class os.windows.native_api.FileInfo

Declaration of structures returned by QueryInformationFile.

class Names

File names information class.

class_id = 12
class ReparsePoint

Bases: ctypes.Structure

Reparse point information structure.

_fields_ = [('file_reference',), ('tag',)]
class_id = 33
class Disposition

Bases: ctypes.Structure

File disposition information structure.

_fields_ = [('delete_file',)]
class_id = 13
class Internal

Bases: ctypes.Structure

File internal information structure.

_fields_ = [('index_number',)]
class_id = 6
class Rename

Bases: ctypes.Structure

File rename information structure.

_fields_ = []
class_id = 10
class Basic

Bases: ctypes.Structure

Basic file information structure.

_fields_ = [('creation_time',), ('last_access_time',), ('last_write_time',), ('change_time',), ('file_attributes',)]
class_id = 4
__str__() str

Return string representation of basic file information.

class os.windows.native_api.ObjectInfo

Declaration of structures returned by QueryObjectInformation.

class Name

Bases: ctypes.Structure

Object name information structure.

_fields_ = []
class_id = 1
class os.windows.native_api.ProcessInfo

Declaration of structure returned by QueryInformationProcess.

class Basic

Bases: ctypes.Structure

Basic process information structure.

class_id = 0
_fields_ = [('exit_status',), ('peb',), ('affinity_mask',), ('base_priority',), ('pid',), ('ppid',)]
STILL_ACTIVE = 259
class os.windows.native_api.ObjectAttributes(name: UnicodeString, parent: ctypes.wintypes.HANDLE | None = None)

Bases: ctypes.Structure

OBJECT_ATTRIBUTES structure.

OBJ_CASE_INSENSITIVE = 64
_fields_ = [('length',), ('root_directory',), ('object_name',), ('attributes',), ('security_descriptor',),...
class os.windows.native_api.NT

Container for Windows NT API function bindings.

FindFirstFile
FindClose
FsControlFile
Sleep
GetVolumePathName
SetInformationFile
QueryInformationFile
QueryAttributesFile
OpenFile
QueryDirectoryFile
Close
QueryInformationProcess
WaitForMultipleObjects
OpenProcess
QueryObject
classmethod init_api() None

Init api.

exception os.windows.native_api.NTExceptionError(status: int, message: str, origin: str | None = None)

Bases: e3.error.E3Error

Exception raised for Windows NT API errors.

__str__() str

Return string representation of NT exception with status code.

os.windows.native_api.NTException