Function Reference


Creates or opens a file or I/O device

#include <WinAPIFiles.au3>
_WinAPI_CreateFileEx ( $sFilePath, $iCreation [, $iAccess = 0 [, $iShare = 0 [, $iFlagsAndAttributes = 0 [, $tSecurity = 0 [, $hTemplate = 0]]]]] )


$sFilePath The name of the file or device to be created or opened.
$iCreation The action to take on a file or device that exists or does not exist. This parameter must be one of the following values, which cannot be combined.
$iAccess [optional] The requested access to the file or device, which can be summarized as read, write, both or neither (zero) (Default).
    (See MSDN for more information)
$iShare [optional] The requested sharing mode of the file or device, which can be read, write, both, delete, all of these, or none.
If this parameter is 0 (Default) and _WinAPI_CreateFileEx() succeeds, the file or device cannot be shared and cannot be opened again until the handle to the file or device is closed.
$iFlagsAndAttributes [optional] The file or device attributes and flags. This parameter can be one or more of the following values:


$tSecurity [optional] $tagSECURITY_ATTRIBUTES structure that contains two separate but related data members: an optional security descriptor, and a Boolean value that determines whether the returned handle can be inherited by child processes.
If this parameter is 0 (Default), the handle cannot be inherited by any child processes the application may create and the file or device associated with the returned handle gets a default security descriptor.
$hTemplate [optional] Handle to a template file with the $GENERIC_READ access right. The template file supplies file attributes and extended attributes for the file that is being created.

Return Value

Success: Handle to the specified file, device, named pipe, or mail slot.
Failure: 0 and sets the @error flag to non-zero, @extended contains _WinAPI_GetLastError().


When an application is finished using the object handle returned by this function, use the _WinAPI_CloseHandle() function to close the handle.
This not only frees up system resources, but can have wider influence on things like sharing the file or device and committing data to disk.



See Also

Search CreateFile in MSDN Library.