# Function Reference

# _WinAPI_CreateFileEx

Creates or opens a file or I/O device

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

## Parameters

$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. $CREATE_NEW $CREATE_ALWAYS $OPEN_EXISTING $OPEN_ALWAYS $TRUNCATE_EXISTING
$iAccess | [optional] The requested access to the file or device, which can be summarized as read, write, both or neither (zero) (Default). $GENERIC_READ $GENERIC_WRITE (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. $FILE_SHARE_DELETE $FILE_SHARE_READ $FILE_SHARE_WRITE
$iFlagsAndAttributes | [optional] The file or device attributes and flags. This parameter can be one or more of the following values: $FILE_ATTRIBUTE_READONLY $FILE_ATTRIBUTE_HIDDEN $FILE_ATTRIBUTE_SYSTEM $FILE_ATTRIBUTE_DIRECTORY $FILE_ATTRIBUTE_ARCHIVE $FILE_ATTRIBUTE_DEVICE $FILE_ATTRIBUTE_NORMAL $FILE_ATTRIBUTE_TEMPORARY $FILE_ATTRIBUTE_SPARSE_FILE $FILE_ATTRIBUTE_REPARSE_POINT $FILE_ATTRIBUTE_COMPRESSED $FILE_ATTRIBUTE_OFFLINE $FILE_ATTRIBUTE_NOT_CONTENT_INDEXED $FILE_ATTRIBUTE_ENCRYPTED $FILE_FLAG_BACKUP_SEMANTICS $FILE_FLAG_DELETE_ON_CLOSE $FILE_FLAG_NO_BUFFERING $FILE_FLAG_OPEN_NO_RECALL $FILE_FLAG_OPEN_REPARSE_POINT $FILE_FLAG_OVERLAPPED $FILE_FLAG_POSIX_SEMANTICS $FILE_FLAG_RANDOM_ACCESS $FILE_FLAG_SEQUENTIAL_SCAN $FILE_FLAG_WRITE_THROUGH $SECURITY_ANONYMOUS (Default) $SECURITY_CONTEXT_TRACKING $SECURITY_DELEGATION $SECURITY_EFFECTIVE_ONLY $SECURITY_IDENTIFICATION $SECURITY_IMPERSONATION
$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().

## Remarks

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.

## Related

_WinAPI_CloseHandle

## See Also

Search CreateFile in MSDN Library.