CreateFile
Déclaration
- C:\lazarus2.0.2\fpc\3.0.4\source\rtl\win\wininc\ascdef.inc
function CreateFile(lpFileName:LPCSTR; dwDesiredAccess:DWORD; dwShareMode:DWORD; lpSecurityAttributes:LPSECURITY_ATTRIBUTES; dwCreationDisposition:DWORD;dwFlagsAndAttributes:DWORD; hTemplateFile:HANDLE):HANDLE; external 'kernel32' name 'CreateFileA';
Exemple d'utilisation
Result := CreateFile( PChar(AFile), GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
Paramétres
lpFileName
pointeur vers le nom du fichier PChar(AFilename)
dwDesiredAccess
0
: l'application peut interroger certaines métadonnées telles que les attributs de fichiers, de répertoires ou de périphériques sans accéder à ces fichiers ou périphériques.GENERIC_READ
($8000 0000) : Accés en écritureGENERIC_WRITE
($4000 0000) : Accés en LectureGENERIC_READ or GENERIC_WRITE
($C000 0000): Accés en écriture et lectureFILE_ADD_FILE
(2) : Pour un répertoire, le froits de créer un fichier dans ce répertoire.FILE_ADD_SUBDIRECTORY
(4) : For a directory, the right to create a subdirectory.FILE_ALL_ACCESS
: All possible access rights for a file.FILE_APPEND_DATA
(4) :- Pour un fichier : the right to append data to the file. (For local files, write operations will not overwrite existing data if this flag is specified without
FILE_WRITE_DATA
.) - Pour un répertoire: the right to create a subdirectory (
FILE_ADD_SUBDIRECTORY
).
FILE_CREATE_PIPE_INSTANCE
(4) : For a named pipe, the right to create a pipe.FILE_DELETE_CHILD
($40) : For a directory, the right to delete a directory and all the files it contains, including read-only files.FILE_EXECUTE
($20) : For a native code file, the right to execute the file. This access right given to scripts may cause the script to be executable, depending on the script interpreter.FILE_LIST_DIRECTORY
(1) : For a directory, the right to list the contents of the directory.FILE_READ_ATTRIBUTES
(128/$80) :The right to read file attributes.FILE_READ_DATA
(1) : For a file object, the right to read the corresponding file data. For a directory object, the right to read the corresponding directory data.FILE_READ_EA
(8) : The right to read extended file attributes.FILE_TRAVERSE
(32/$20) : For a directory, the right to traverse the directory. By default, users are assigned the BYPASS_TRAVERSE_CHECKING privilege, which ignores the FILE_TRAVERSE access right. See the remarks in File Security and Access Rights for more information.FILE_WRITE_ATTRIBUTES
(256/$100) : The right to write file attributes.FILE_WRITE_DATA
(2) : For a file object, the right to write data to the file. For a directory object, the right to create a file in the directory (FILE_ADD_FILE).FILE_WRITE_EA
(16/$10) : The right to write extended file attributes.STANDARD_RIGHTS_READ
: Includes READ_CONTROL, which is the right to read the information in the file or directory object's security descriptor. This does not include the information in the SACL.STANDARD_RIGHTS_WRITE
: Same as STANDARD_RIGHTS_READ.
Vous ne pouvez pas demander un mode d'accès qui entre en conflit avec le mode de partage spécifié par le paramètre dwShareMode dans une requête ouverte qui a déjà un identifiant ouvert.
Apparement pour lire des données SMART sur un disque, il doit etre ouvert en
GENERIC_READ or GENERIC_WRITE
dwShareMode
- 0 ($0) : Empêche les autres processus d'ouvrir un fichier ou un périphérique s'ils demandent un accès en suppression, en lecture ou en écriture.
FILE_SHARE_DELETE
($4) : Permet aux opérations d'ouverture ultérieures sur un fichier ou un périphérique de demander un accès de suppression.
Sinon, les autres processus ne peuvent pas ouvrir le fichier ou le périphérique s'ils demandent un accès par suppression.
Si cet indicateur n'est pas spécifié, mais que le fichier ou le périphérique a été ouvert pour un accès par suppression, la fonction échoue.
Remarque L'accès par suppression autorise les opérations de suppression et de renommage.FILE_SHARE_READ
($1) : Permet aux opérations d'ouverture ultérieures sur un fichier ou un périphérique de demander un accès en lecture.
Sinon, les autres processus ne peuvent pas ouvrir le fichier ou le périphérique s'ils demandent un accès en lecture.
Si cet indicateur n'est pas spécifié, mais que le fichier ou le périphérique a été ouvert en lecture, la fonction échoue.FILE_SHARE_WRITE
($2) : Permet aux opérations d'ouverture ultérieures sur un fichier ou un périphérique de demander un accès en écriture.
Sinon, les autres processus ne peuvent pas ouvrir le fichier ou le périphérique s'ils demandent un accès en écriture.
Si cet indicateur n'est pas spécifié, mais que le fichier ou le périphérique a été ouvert pour l'accès en écriture ou possède un mappage de fichier avec accès en écriture, la fonction échoue.
lpSecurityAttributes
dwCreationDisposition
CREATE_ALWAYS
($2) : Creates a new file, always.
If the specified file exists and is writable, the function overwrites the file, the function succeeds, and last-error code is set to ERROR_ALREADY_EXISTS (183).
If the specified file does not exist and is a valid path, a new file is created, the function succeeds, and the last-error code is set to zero.CREATE_NEW
($1) : Creates a new file, only if it does not already exist.
If the specified file exists, the function fails and the last-error code is set to ERROR_FILE_EXISTS (80).
If the specified file does not exist and is a valid path to a writable location, a new file is created.OPEN_ALWAYS
($4) : Opens a file, always.
If the specified file exists, the function succeeds and the last-error code is set to ERROR_ALREADY_EXISTS (183).
If the specified file does not exist and is a valid path to a writable location, the function creates a file and the last-error code is set to zero.OPEN_EXISTING
($3) : Opens a file or device, only if it exists.
If the specified file or device does not exist, the function fails and the last-error code is set to ERROR_FILE_NOT_FOUND (2).TRUNCATE_EXISTING
($5) : Opens a file and truncates it so that its size is zero bytes, only if it exists.
If the specified file does not exist, the function fails and the last-error code is set to ERROR_FILE_NOT_FOUND (2).
The calling process must open the file with theGENERIC_WRITE
bit set as part of thedwDesiredAccess
parameter.
dwFlagsAndAttributes
FILE_ATTRIBUTE_ARCHIVE
(32/$20) : The file should be archived. Applications use this attribute to mark files for backup or removal.
.FILE_ATTRIBUTE_ENCRYPTED
(16384/$4000) : The file or directory is encrypted. For a file, this means that all data in the file is encrypted. For a directory, this means that encryption is the default for newly created files and subdirectories. For more information, see File Encryption.
This flag has no effect ifFILE_ATTRIBUTE_SYSTEM
is also specified.
This flag is not supported on Home, Home Premium, Starter, or ARM editions of Windows.FILE_ATTRIBUTE_HIDDEN
($2) : The file is hidden. Do not include it in an ordinary directory listing.FILE_ATTRIBUTE_NORMAL
(128/$80) : The file does not have other attributes set. This attribute is valid only if used alone.FILE_ATTRIBUTE_OFFLINE
(4096/$1000) : The data of a file is not immediately available. This attribute indicates that file data is physically moved to offline storage. This attribute is used by Remote Storage, the hierarchical storage management software. Applications should not arbitrarily change this attribute.FILE_ATTRIBUTE_READONLY
($1) : The file is read only. Applications can read the file, but cannot write to or delete it.FILE_ATTRIBUTE_SYSTEM
($4) : The file is part of or used exclusively by an operating system.FILE_ATTRIBUTE_TEMPORARY
(256/$100) : The file is being used for temporary storage.
For more information, see the Caching Behavior section of this topic.FILE_FLAG_BACKUP_SEMANTICS
($200 0000) : Le fichier va être ouvert ou créé pour une opération de sauvegarde ou de restauration.
Le système veille à ce que le processus appelant passe outre les contrôles de sécurité des fichiers lorsque le processus dispose des privilègesSE_BACKUP_NAME
etSE_RESTORE_NAME
.
Pour plus d'informations, voir Modification des privilèges dans un jeton.
Vous devez définir cet indicateur pour obtenir un identifiant pour un répertoire.
Un identifiant de répertoire peut être transmis à certaines fonctions à la place d'un identifiant de fichier.
Pour plus d'informations, consultez la section Remarques.FILE_FLAG_DELETE_ON_CLOSE
($400 0000) : The file is to be deleted immediately after all of its handles are closed, which includes the specified handle and any other open or duplicated handles.
If there are existing open handles to a file, the call fails unless they were all opened with theFILE_SHARE_DELETE
share mode.
Subsequent open requests for the file fail, unless the FILE_SHARE_DELETE share mode is specified.FILE_FLAG_NO_BUFFERING
($2000 0000) : The file or device is being opened with no system caching for data reads and writes. This flag does not affect hard disk caching or memory mapped files.
There are strict requirements for successfully working with files opened with CreateFile using theFILE_FLAG_NO_BUFFERING
flag, for details see File Buffering.FILE_FLAG_OPEN_NO_RECALL
($10 0000) : The file data is requested, but it should continue to be located in remote storage. It should not be transported back to local storage. This flag is for use by remote storage systems.FILE_FLAG_OPEN_REPARSE_POINT
($20 0000) : Normal reparse point processing will not occur; CreateFile will attempt to open the reparse point. When a file is opened, a file handle is returned, whether or not the filter that controls the reparse point is operational.
This flag cannot be used with theCREATE_ALWAYS
flag.
If the file is not a reparse point, then this flag is ignored.FILE_FLAG_OVERLAPPED
($4000 0000) : Le fichier ou le périphérique est en train d'être ouvert ou créé pour des E/S asynchrones.
Lorsque les opérations d'E/S suivantes sont terminées sur ce handle, l'événement spécifié dans la structure OVERLAPPED sera mis à l'état signalé.
Si cet indicateur est spécifié, le fichier peut être utilisé pour des opérations de lecture et d'écriture simultanées.
Si cet indicateur n'est pas spécifié, les opérations d'E/S sont sérialisées, même si les appels aux fonctions de lecture et d'écriture spécifient une structure OVERLAPPED.
Pour plus d'informations sur les considérations relatives à l'utilisation d'un handle de fichier créé avec cet indicateur, reportez-vous à la section Manipulations d'E/S synchrones et asynchrones de cette rubrique.FILE_FLAG_POSIX_SEMANTICS
($100 0000) : Access will occur according to POSIX rules. This includes allowing multiple files with names, differing only in case, for file systems that support that naming. Use care when using this option, because files created with this flag may not be accessible by applications that are written for MS-DOS or 16-bit Windows.FILE_FLAG_RANDOM_ACCESS
($1000 0000) : Access is intended to be random. The system can use this as a hint to optimize file caching.
This flag has no effect if the file system does not support cached I/O and FILE_FLAG_NO_BUFFERING.
For more information, see the Caching Behavior section of this topic.FILE_FLAG_SESSION_AWARE
($80 0000) : The file or device is being opened with session awareness. If this flag is not specified, then per-session devices (such as a device using RemoteFX USB Redirection) cannot be opened by processes running in session 0. This flag has no effect for callers not in session 0. This flag is supported only on server editions of Windows.
Windows Server 2008 R2 and Windows Server 2008: This flag is not supported before Windows Server 2012.FILE_FLAG_SEQUENTIAL_SCAN
($800 0000) : Access is intended to be sequential from beginning to end. The system can use this as a hint to optimize file caching.
This flag should not be used if read-behind (that is, reverse scans) will be used.
This flag has no effect if the file system does not support cached I/O andFILE_FLAG_NO_BUFFERING
.
For more information, see the Caching Behavior section of this topic.FILE_FLAG_WRITE_THROUGH
($8000 0000) : Write operations will not go through any intermediate cache, they will go directly to disk.
For additional information, see the Caching Behavior section of this topic.SECURITY_ANONYMOUS
: Impersonates a client at the Anonymous impersonation level.SECURITY_CONTEXT_TRACKING
: The security tracking mode is dynamic. If this flag is not specified, the security tracking mode is static.SECURITY_DELEGATION
: Impersonates a client at the Delegation impersonation level.SECURITY_EFFECTIVE_ONLY
: Only the enabled aspects of the client's security context are available to the server. If you do not specify this flag, all aspects of the client's security context are available.
This allows the client to limit the groups and privileges that a server can use while impersonating the client.SECURITY_IDENTIFICATION
: Impersonates a client at the Identification impersonation level.SECURITY_IMPERSONATION
: Impersonate a client at the impersonation level. This is the default behavior if no other flags are specified along with theSECURITY_SQOS_PRESENT
flag.
hTemplateFile
Retourne : Handle
Vous pourriez laisser un commentaire si vous étiez connecté.