using System; using System.IO; using System.Runtime.InteropServices; using System.Text; namespace Vanara.PInvoke { public static partial class Kernel32 { /// /// /// [Microsoft strongly recommends developers utilize alternative means to achieve your application’s needs. Many scenarios that TxF /// was developed for can be achieved through simpler and more readily available techniques. Furthermore, TxF may not be available in /// future versions of Microsoft Windows. For more information, and alternatives to TxF, please see /// /// Alternatives to using Transactional NTFS /// .] /// /// Copies an existing file to a new file as a transacted operation, notifying the application of its progress through a callback function. /// /// /// /// The name of an existing file. /// /// In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide /// characters, call the Unicode version of the function and prepend "\?" to the path. For more information, see Naming a File. /// /// If does not exist, the CopyFileTransacted function fails, and the GetLastError function returns ERROR_FILE_NOT_FOUND. /// The file must reside on the local computer; otherwise, the function fails and the last error code is set to ERROR_TRANSACTIONS_UNSUPPORTED_REMOTE. /// /// /// The name of the new file. /// /// In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide /// characters, call the Unicode version of the function and prepend "\?" to the path. For more information, see Naming a File. /// /// /// /// /// The address of a callback function of type LPPROGRESS_ROUTINE that is called each time another portion of the file has /// been copied. This parameter can be NULL. For more information on the progress callback function, see the /// CopyProgressRoutine function. /// /// /// /// The argument to be passed to the callback function. This parameter can be NULL. /// /// /// /// If this flag is set to TRUE during the copy operation, the operation is canceled. Otherwise, the copy operation will /// continue to completion. /// /// /// /// Flags that specify how the file is to be copied. This parameter can be a combination of the following values. /// /// /// Value /// Meaning /// /// /// COPY_FILE_COPY_SYMLINK 0x00000800 /// /// If the source file is a symbolic link, the destination file is also a symbolic link pointing to the same file that the source /// symbolic link is pointing to. /// /// /// /// COPY_FILE_FAIL_IF_EXISTS 0x00000001 /// The copy operation fails immediately if the target file already exists. /// /// /// COPY_FILE_OPEN_SOURCE_FOR_WRITE 0x00000004 /// The file is copied and the original file is opened for write access. /// /// /// COPY_FILE_RESTARTABLE 0x00000002 /// /// Progress of the copy is tracked in the target file in case the copy fails. The failed copy can be restarted at a later time by /// specifying the same values for and as those used in the call that failed. This can significantly slow down the copy operation as /// the new file may be flushed multiple times during the copy operation. /// /// /// /// /// /// A handle to the transaction. This handle is returned by the CreateTransaction function. /// /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. To get extended error information call GetLastError. /// /// If returns PROGRESS_CANCEL due to the user canceling the operation, CopyFileTransacted will return zero and /// GetLastError will return ERROR_REQUEST_ABORTED. In this case, the partially copied destination file is deleted. /// /// /// If returns PROGRESS_STOP due to the user stopping the operation, CopyFileTransacted will return zero and /// GetLastError will return ERROR_REQUEST_ABORTED. In this case, the partially copied destination file is left intact. /// /// /// If you attempt to call this function with a handle to a transaction that has already been rolled back, CopyFileTransacted /// will return either ERROR_TRANSACTION_NOT_ACTIVE or ERROR_INVALID_TRANSACTION. /// /// /// /// /// This function preserves extended attributes, OLE structured storage, NTFS file system alternate data streams, security /// attributes, and file attributes. /// /// /// Windows 7, Windows Server 2008 R2, Windows Server 2008 and Windows Vista: Security resource attributes ( /// ATTRIBUTE_SECURITY_INFORMATION) for the existing file are not copied to the new file until Windows 8 and Windows Server 2012. /// /// /// This function fails with ERROR_ACCESS_DENIED if the destination file already exists and has the /// FILE_ATTRIBUTE_HIDDEN or FILE_ATTRIBUTE_READONLY attribute set. /// /// Encrypted files are not supported by TxF. /// If COPY_FILE_COPY_SYMLINK is specified, the following rules apply: /// /// If the source file is a symbolic link, the symbolic link is copied, not the target file. /// If the source file is not a symbolic link, there is no change in behavior. /// If the destination file is an existing symbolic link, the symbolic link is overwritten, not the target file. /// /// If COPY_FILE_FAIL_IF_EXISTS is also specified, and the destination file is an existing symbolic link, the operation fails /// in all cases. /// /// /// If /// COPY_FILE_COPY_SYMLINK /// is not specified, the following rules apply: /// /// /// If COPY_FILE_FAIL_IF_EXISTS is also specified, and the destination file is an existing symbolic link, the operation fails /// only if the target of the symbolic link exists. /// /// If COPY_FILE_FAIL_IF_EXISTS is not specified, there is no change in behavior. /// /// Link tracking is not supported by TxF. /// In Windows 8 and Windows Server 2012, this function is supported by the following technologies. /// /// /// Technology /// Supported /// /// /// Server Message Block (SMB) 3.0 protocol /// No /// /// /// SMB 3.0 Transparent Failover (TFO) /// No /// /// /// SMB 3.0 with Scale-out File Shares (SO) /// No /// /// /// Cluster Shared Volume File System (CsvFS) /// No /// /// /// Resilient File System (ReFS) /// No /// /// /// Note that SMB 3.0 does not support TxF. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-copyfiletransacteda BOOL CopyFileTransactedA( LPCSTR // lpExistingFileName, LPCSTR lpNewFileName, LPPROGRESS_ROUTINE lpProgressRoutine, LPVOID lpData, LPBOOL pbCancel, DWORD dwCopyFlags, // HANDLE hTransaction ); [DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winbase.h", MSDNShortId = "118392de-166b-413e-99c9-b3deb756de0e")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool CopyFileTransacted(string lpExistingFileName, string lpNewFileName, CopyProgressRoutine lpProgressRoutine, [Optional] IntPtr lpData, [MarshalAs(UnmanagedType.Bool)] ref bool pbCancel, COPY_FILE dwCopyFlags, HTRXN hTransaction); /// /// /// [Microsoft strongly recommends developers utilize alternative means to achieve your application’s needs. Many scenarios that TxF /// was developed for can be achieved through simpler and more readily available techniques. Furthermore, TxF may not be available in /// future versions of Microsoft Windows. For more information, and alternatives to TxF, please see /// /// Alternatives to using Transactional NTFS /// .] /// /// Creates a new directory as a transacted operation, with the attributes of a specified template directory. If the underlying file /// system supports security on files and directories, the function applies a specified security descriptor to the new directory. The /// new directory retains the other attributes of the specified template directory. /// /// /// /// The path of the directory to use as a template when creating the new directory. This parameter can be NULL. /// /// In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide /// characters, call the Unicode version of the function and prepend "\?" to the path. For more information, see Naming a File. /// /// The directory must reside on the local computer; otherwise, the function fails and the last error code is set to ERROR_TRANSACTIONS_UNSUPPORTED_REMOTE. /// /// /// The path of the directory to be created. /// /// In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide /// characters, call the Unicode version of the function and prepend "\?" to the path. For more information, see Naming a File. /// /// /// /// /// A pointer to a SECURITY_ATTRIBUTES structure. The lpSecurityDescriptor member of the structure specifies a security /// descriptor for the new directory. /// /// /// If is NULL, the directory gets a default security descriptor. The access control lists (ACL) in the default security /// descriptor for a directory are inherited from its parent directory. /// /// /// The target file system must support security on files and directories for this parameter to have an effect. This is indicated /// when GetVolumeInformation returns FS_PERSISTENT_ACLS. /// /// /// /// A handle to the transaction. This handle is returned by the CreateTransaction function. /// /// /// If the function succeeds, the return value is nonzero. /// /// If the function fails, the return value is zero (0). To get extended error information, call GetLastError. Possible errors /// include the following. /// /// /// /// Return code /// Description /// /// /// ERROR_ALREADY_EXISTS /// The specified directory already exists. /// /// /// ERROR_EFS_NOT_ALLOWED_IN_TRANSACTION /// You cannot create a child directory with a parent directory that has encryption disabled. /// /// /// ERROR_PATH_NOT_FOUND /// One or more intermediate directories do not exist. This function only creates the final directory in the path. /// /// /// /// /// /// The CreateDirectoryTransacted function allows you to create directories that inherit stream information from other /// directories. This function is useful, for example, when you are using Macintosh directories, which have a resource stream that is /// needed to properly identify directory contents as an attribute. /// /// /// Some file systems, such as the NTFS file system, support compression or encryption for individual files and directories. On /// volumes formatted for such a file system, a new directory inherits the compression and encryption attributes of its parent directory. /// /// /// This function fails with ERROR_EFS_NOT_ALLOWED_IN_TRANSACTION if you try to create a child directory with a parent /// directory that has encryption disabled. /// /// /// You can obtain a handle to a directory by calling the CreateFileTransacted function with the FILE_FLAG_BACKUP_SEMANTICS /// flag set. /// /// In Windows 8 and Windows Server 2012, this function is supported by the following technologies. /// /// /// Technology /// Supported /// /// /// Server Message Block (SMB) 3.0 protocol /// No /// /// /// SMB 3.0 Transparent Failover (TFO) /// No /// /// /// SMB 3.0 with Scale-out File Shares (SO) /// No /// /// /// Cluster Shared Volume File System (CsvFS) /// No /// /// /// Resilient File System (ReFS) /// No /// /// /// SMB 3.0 does not support TxF. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-createdirectorytransacteda BOOL // CreateDirectoryTransactedA( LPCSTR lpTemplateDirectory, LPCSTR lpNewDirectory, LPSECURITY_ATTRIBUTES lpSecurityAttributes, HANDLE // hTransaction ); [DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winbase.h", MSDNShortId = "75663b30-5bd9-4de7-8e4f-dc58016c2c40")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool CreateDirectoryTransacted(string lpTemplateDirectory, string lpNewDirectory, SECURITY_ATTRIBUTES lpSecurityAttributes, HTRXN hTransaction); /// /// /// [Microsoft strongly recommends developers utilize alternative means to achieve your application’s needs. Many scenarios that TxF /// was developed for can be achieved through simpler and more readily available techniques. Furthermore, TxF may not be available in /// future versions of Microsoft Windows. For more information, and alternatives to TxF, please see /// /// Alternatives to using Transactional NTFS /// .] /// /// Creates or opens a file, file stream, or directory as a transacted operation. The function returns a handle that can be used to /// access the object. /// /// /// To perform this operation as a non-transacted operation or to access objects other than files (for example, named pipes, physical /// devices, mailslots), use the CreateFile function. /// /// For more information about transactions, see the Remarks section of this topic. /// /// /// The name of an object to be created or opened. /// The object must reside on the local computer; otherwise, the function fails and the last error code is set to ERROR_TRANSACTIONS_UNSUPPORTED_REMOTE. /// /// In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide /// characters, call the Unicode version of the function and prepend "\?" to the path. For more information, see Naming a File. For /// information on special device names, see Defining an MS-DOS Device Name. /// /// /// To create a file stream, specify the name of the file, a colon, and then the name of the stream. For more information, see File Streams. /// /// /// /// /// The access to the object, which can be summarized as read, write, both or neither (zero). The most commonly used values are /// GENERIC_READ, GENERIC_WRITE, or both ( GENERIC_READ | GENERIC_WRITE). For more information, see /// Generic Access Rights and File Security and Access Rights. /// /// /// If this parameter is zero, the application can query file, directory, or device attributes without accessing that file or device. /// For more information, see the Remarks section of this topic. /// /// /// You cannot request an access mode that conflicts with the sharing mode that is specified in an open request that has an open /// handle. For more information, see Creating and Opening Files. /// /// /// /// The sharing mode of an object, which can be read, write, both, delete, all of these, or none (refer to the following table). /// /// If this parameter is zero and CreateFileTransacted succeeds, the object cannot be shared and cannot be opened again until /// the handle is closed. For more information, see the Remarks section of this topic. /// /// /// You cannot request a sharing mode that conflicts with the access mode that is specified in an open request that has an open /// handle, because that would result in the following sharing violation: ERROR_SHARING_VIOLATION. For more information, see /// Creating and Opening Files. /// /// /// To enable a process to share an object while another process has the object open, use a combination of one or more of the /// following values to specify the access mode they can request to open the object. /// /// /// Note The sharing options for each open handle remain in effect until that handle is closed, regardless of process context. /// /// /// /// Value /// Meaning /// /// /// 0 0x00000000 /// Disables subsequent open operations on an object to request any type of access to that object. /// /// /// FILE_SHARE_DELETE 0x00000004 /// /// Enables subsequent open operations on an object to request delete access. Otherwise, other processes cannot open the object if /// they request delete access. If this flag is not specified, but the object has been opened for delete access, the function fails. /// /// /// /// FILE_SHARE_READ 0x00000001 /// /// Enables subsequent open operations on an object to request read access. Otherwise, other processes cannot open the object if they /// request read access. If this flag is not specified, but the object has been opened for read access, the function fails. /// /// /// /// FILE_SHARE_WRITE 0x00000002 /// /// Enables subsequent open operations on an object to request write access. Otherwise, other processes cannot open the object if /// they request write access. If this flag is not specified, but the object has been opened for write access or has a file mapping /// with write access, the function fails. /// /// /// /// /// /// /// A pointer to a SECURITY_ATTRIBUTES structure that contains an optional security descriptor and also determines whether or not the /// returned handle can be inherited by child processes. The parameter can be NULL. /// /// /// If the parameter is NULL, the handle returned by CreateFileTransacted cannot be inherited by any child processes /// your application may create and the object associated with the returned handle gets a default security descriptor. /// /// The bInheritHandle member of the structure specifies whether the returned handle can be inherited. /// /// The lpSecurityDescriptor member of the structure specifies a security descriptor for an object, but may also be NULL. /// /// /// If lpSecurityDescriptor member is NULL, the object associated with the returned handle is assigned a default /// security descriptor. /// /// /// CreateFileTransacted ignores the lpSecurityDescriptor member when opening an existing file, but continues to use /// the bInheritHandle member. /// /// For more information, see the Remarks section of this topic. /// /// /// An action to take on files that exist and do not exist. /// For more information, see the Remarks section of this topic. /// This parameter must be one of the following values, which cannot be combined. /// /// /// Value /// Meaning /// /// /// 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. For more information, see the Remarks section /// of this topic. /// /// /// /// 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 does not exist, the function fails and the last-error code is /// set to ERROR_FILE_NOT_FOUND (2). For more information, see the Remarks section of this topic. /// /// /// /// 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 the /// GENERIC_WRITE bit set as part of the parameter. /// /// /// /// /// /// The file attributes and flags, FILE_ATTRIBUTE_NORMAL being the most common default value. /// /// This parameter can include any combination of the available file attributes ( FILE_ATTRIBUTE_*). All other file attributes /// override FILE_ATTRIBUTE_NORMAL. /// /// /// This parameter can also contain combinations of flags ( FILE_FLAG_) for control of buffering behavior, access modes, and /// other special-purpose flags. These combine with any FILE_ATTRIBUTE_ values. /// /// /// This parameter can also contain Security Quality of Service (SQOS) information by specifying the SECURITY_SQOS_PRESENT /// flag. Additional SQOS-related flags information is presented in the table following the attributes and flags tables. /// /// /// Note When CreateFileTransacted opens an existing file, it generally combines the file flags with the file /// attributes of the existing file, and ignores any file attributes supplied as part of . Special cases are detailed in Creating and /// Opening Files. /// /// The following file attributes and flags are used only for file objects, not other types of objects that /// CreateFileTransacted /// /// opens (additional information can be found in the Remarks section of this topic). For more advanced access to file attributes, see /// /// SetFileAttributes /// . For a complete list of all file attributes with their values and descriptions, see /// File Attribute Constants /// . /// /// /// Attribute /// Meaning /// /// /// FILE_ATTRIBUTE_ARCHIVE 32 (0x20) /// The file should be archived. Applications use this attribute to mark files for backup or removal. /// /// /// FILE_ATTRIBUTE_ENCRYPTED 16384 (0x4000) /// /// 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 if FILE_ATTRIBUTE_SYSTEM is also specified. /// /// /// /// FILE_ATTRIBUTE_HIDDEN 2 (0x2) /// The file is hidden. Do not include it in an ordinary directory listing. /// /// /// FILE_ATTRIBUTE_NORMAL 128 (0x80) /// The file does not have other attributes set. This attribute is valid only if used alone. /// /// /// FILE_ATTRIBUTE_OFFLINE 4096 (0x1000) /// /// 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 (0x1) /// The file is read only. Applications can read the file, but cannot write to or delete it. /// /// /// FILE_ATTRIBUTE_SYSTEM 4 (0x4) /// The file is part of or used exclusively by an operating system. /// /// /// FILE_ATTRIBUTE_TEMPORARY 256 (0x100) /// /// The file is being used for temporary storage. File systems avoid writing data back to mass storage if sufficient cache memory is /// available, because an application deletes a temporary file after a handle is closed. In that case, the system can entirely avoid /// writing the data. Otherwise, the data is written after the handle is closed. /// /// /// /// /// /// Flag /// Meaning /// /// /// FILE_FLAG_BACKUP_SEMANTICS 0x02000000 /// /// The file is being opened or created for a backup or restore operation. The system ensures that the calling process overrides file /// security checks when the process has SE_BACKUP_NAME and SE_RESTORE_NAME privileges. For more information, see Changing Privileges /// in a Token. You must set this flag to obtain a handle to a directory. A directory handle can be passed to some functions instead /// of a file handle. For more information, see Directory Handles. /// /// /// /// FILE_FLAG_DELETE_ON_CLOSE 0x04000000 /// /// The file is to be deleted immediately after the last transacted writer handle to the file is closed, provided that the /// transaction is still active. If a file has been marked for deletion and a transacted writer handle is still open after the /// transaction completes, the file will not be deleted. If there are existing open handles to a file, the call fails unless they /// were all opened with the FILE_SHARE_DELETE share mode. Subsequent open requests for the file fail, unless the FILE_SHARE_DELETE /// share mode is specified. /// /// /// /// FILE_FLAG_NO_BUFFERING 0x20000000 /// /// The file is being opened with no system caching. This flag does not affect hard disk caching or memory mapped files. When /// combined with FILE_FLAG_OVERLAPPED, the flag gives maximum asynchronous performance, because the I/O does not rely on the /// synchronous operations of the memory manager. However, some I/O operations take more time, because data is not being held in the /// cache. Also, the file metadata may still be cached. To flush the metadata to disk, use the FlushFileBuffers function. An /// application must meet certain requirements when working with files that are opened with FILE_FLAG_NO_BUFFERING: One way to align /// buffers on integer multiples of the volume sector size is to use VirtualAlloc to allocate the buffers. It allocates memory that /// is aligned on addresses that are integer multiples of the operating system's memory page size. Because both memory page and /// volume sector sizes are powers of 2, this memory is also aligned on addresses that are integer multiples of a volume sector size. /// Memory pages are 4 or 8 KB in size; sectors are 512 bytes (hard disks), 2048 bytes (CD), or 4096 bytes (hard disks), and /// therefore, volume sectors can never be larger than memory pages. An application can determine a volume sector size by calling the /// GetDiskFreeSpace function. /// /// /// /// FILE_FLAG_OPEN_NO_RECALL 0x00100000 /// /// 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 0x00200000 /// /// Normal reparse point processing will not occur; CreateFileTransacted 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 the CREATE_ALWAYS flag. If the file is not a reparse point, then this flag is ignored. /// /// /// /// FILE_FLAG_OVERLAPPED 0x40000000 /// /// The file is being opened or created for asynchronous I/O. When the operation is complete, the event specified in the OVERLAPPED /// structure is set to the signaled state. Operations that take a significant amount of time to process return ERROR_IO_PENDING. If /// this flag is specified, the file can be used for simultaneous read and write operations. The system does not maintain the file /// pointer, therefore you must pass the file position to the read and write functions in the OVERLAPPED structure or update the file /// pointer. If this flag is not specified, then I/O operations are serialized, even if the calls to the read and write functions /// specify an OVERLAPPED structure. /// /// /// /// FILE_FLAG_POSIX_SEMANTICS 0x0100000 /// /// The file is to be accessed 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 0x10000000 /// The file is to be accessed randomly. The system can use this as a hint to optimize file caching. /// /// /// FILE_FLAG_SESSION_AWARE 0x00800000 /// /// 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 0x08000000 /// /// The file is to be accessed sequentially from beginning to end. The system can use this as a hint to optimize file caching. If an /// application moves the file pointer for random access, optimum caching may not occur. However, correct operation is still /// guaranteed. Specifying this flag can increase performance for applications that read large files using sequential access. /// Performance gains can be even more noticeable for applications that read large files mostly sequentially, but occasionally skip /// over small ranges of bytes. This flag has no effect if the file system does not support cached I/O and FILE_FLAG_NO_BUFFERING. /// /// /// /// FILE_FLAG_WRITE_THROUGH 0x80000000 /// /// Write operations will not go through any intermediate cache, they will go directly to disk. If FILE_FLAG_NO_BUFFERING is not also /// specified, so that system caching is in effect, then the data is written to the system cache, but is flushed to disk without /// delay. If FILE_FLAG_NO_BUFFERING is also specified, so that system caching is not in effect, then the data is immediately flushed /// to disk without going through the system cache. The operating system also requests a write-through the hard disk cache to /// persistent media. However, not all hardware supports this write-through capability. /// /// /// /// /// The parameter can also specify Security Quality of Service information. For more information, see Impersonation Levels. When the /// calling application specifies the SECURITY_SQOS_PRESENT flag as part of , it can also contain one or more of the following values. /// /// /// /// Security flag /// Meaning /// /// /// 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 the /// SECURITY_SQOS_PRESENT flag. /// /// /// /// /// /// /// A valid 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. This parameter can be NULL. /// /// When opening an existing file, CreateFileTransacted ignores the template file. /// When opening a new EFS-encrypted file, the file inherits the DACL from its parent directory. /// /// /// A handle to the transaction. This handle is returned by the CreateTransaction function. /// /// /// /// The miniversion to be opened. If the transaction specified in is not the transaction that is modifying the file, this parameter /// should be NULL. Otherwise, this parameter can be a miniversion identifier returned by the FSCTL_TXFS_CREATE_MINIVERSION /// control code, or one of the following values. /// /// /// /// Value /// Meaning /// /// /// TXFS_MINIVERSION_COMMITTED_VIEW 0x0000 /// The view of the file as of its last commit. /// /// /// TXFS_MINIVERSION_DIRTY_VIEW 0xFFFF /// The view of the file as it is being modified by the transaction. /// /// /// TXFS_MINIVERSION_DEFAULT_VIEW 0xFFFE /// /// Either the committed or dirty view of the file, depending on the context. A transaction that is modifying the file gets the dirty /// view, while a transaction that is not modifying the file gets the committed view. /// /// /// /// /// /// TBD /// /// /// If the function succeeds, the return value is an open handle to the specified file, device, named pipe, or mail slot. /// If the function fails, the return value is INVALID_HANDLE_VALUE. To get extended error information, call GetLastError. /// /// /// /// When using the handle returned by CreateFileTransacted, use the transacted version of file I/O functions instead of the /// standard file I/O functions where appropriate. For more information, see Programming Considerations for Transactional NTFS. /// /// /// When opening a transacted handle to a directory, that handle must have FILE_WRITE_DATA ( FILE_ADD_FILE) and /// FILE_APPEND_DATA ( FILE_ADD_SUBDIRECTORY) permissions. These are included in FILE_GENERIC_WRITE permissions. /// You should open directories with fewer permissions if you are just using the handle to create files or subdirectories; otherwise, /// sharing violations can occur. /// /// /// You cannot open a file with FILE_EXECUTE access level when that file is a part of another transaction (that is, another /// application opened it by calling CreateFileTransacted). This means that CreateFileTransacted fails if the access /// level FILE_EXECUTE or FILE_ALL_ACCESS is specified /// /// /// When a non-transacted application calls CreateFileTransacted with MAXIMUM_ALLOWED specified for , a handle is /// opened with the same access level every time. When a transacted application calls CreateFileTransacted with /// MAXIMUM_ALLOWED specified for , a handle is opened with a differing amount of access based on whether the file is locked /// by a transaction. For example, if the calling application has FILE_EXECUTE access level for a file, the application only /// obtains this access if the file that is being opened is either not locked by a transaction, or is locked by a transaction and the /// application is already a transacted reader for that file. /// /// See Transactional NTFS for a complete description of transacted operations. /// /// Use the CloseHandle function to close an object handle returned by CreateFileTransacted when the handle is no longer /// needed, and prior to committing or rolling back the transaction. /// /// /// Some file systems, such as the NTFS file system, support compression or encryption for individual files and directories. On /// volumes that are formatted for that kind of file system, a new file inherits the compression and encryption attributes of its directory. /// /// /// You cannot use CreateFileTransacted to control compression on a file or directory. For more information, see File /// Compression and Decompression, and File Encryption. /// /// Symbolic link behavior—If the call to this function creates a new file, there is no change in behavior. /// If FILE_FLAG_OPEN_REPARSE_POINT is specified: /// /// If an existing file is opened and it is a symbolic link, the handle returned is a handle to the symbolic link. /// If TRUNCATE_EXISTING or FILE_FLAG_DELETE_ON_CLOSE are specified, the file affected is a symbolic link. /// /// If /// FILE_FLAG_OPEN_REPARSE_POINT /// is not specified: /// /// If an existing file is opened and it is a symbolic link, the handle returned is a handle to the target. /// /// If CREATE_ALWAYS, TRUNCATE_EXISTING, or FILE_FLAG_DELETE_ON_CLOSE are specified, the file affected is the target. /// /// /// /// A multi-sector write is not guaranteed to be atomic unless you are using a transaction (that is, the handle created is a /// transacted handle). A single-sector write is atomic. Multi-sector writes that are cached may not always be written to the disk; /// therefore, specify /// /// FILE_FLAG_WRITE_THROUGH /// to ensure that an entire multi-sector write is written to the disk without caching. /// /// As stated previously, if the parameter is NULL, the handle returned by CreateFileTransacted cannot be inherited by /// any child processes your application may create. The following information regarding this parameter also applies: /// /// /// /// If bInheritHandle is not FALSE, which is any nonzero value, then the handle can be inherited. Therefore it is /// critical this structure member be properly initialized to FALSE if you do not intend the handle to be inheritable. /// /// /// The access control lists (ACL) in the default security descriptor for a file or directory are inherited from its parent directory. /// /// /// The target file system must support security on files and directories for the lpSecurityDescriptor to have an effect on /// them, which can be determined by using GetVolumeInformation /// /// /// In Windows 8 and Windows Server 2012, this function is supported by the following technologies. /// /// /// Technology /// Supported /// /// /// Server Message Block (SMB) 3.0 protocol /// No /// /// /// SMB 3.0 Transparent Failover (TFO) /// No /// /// /// SMB 3.0 with Scale-out File Shares (SO) /// No /// /// /// Cluster Shared Volume File System (CsvFS) /// No /// /// /// Resilient File System (ReFS) /// No /// /// /// Note that SMB 3.0 does not support TxF. /// Files /// /// If you try to create a file on a floppy drive that does not have a floppy disk or a CD-ROM drive that does not have a CD, the /// system displays a message for the user to insert a disk or a CD. To prevent the system from displaying this message, call the /// /// SetErrorMode /// function with /// SEM_FAILCRITICALERRORS /// . /// For more information, see Creating and Opening Files. /// /// If you rename or delete a file and then restore it shortly afterward, the system searches the cache for file information to /// restore. Cached information includes its short/long name pair and creation time. /// /// /// If you call CreateFileTransacted on a file that is pending deletion as a result of a previous call to DeleteFile, the /// function fails. The operating system delays file deletion until all handles to the file are closed. GetLastError returns ERROR_ACCESS_DENIED. /// /// /// The 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. See Obtaining and Setting File Information and GetFileInformationByHandle. /// /// /// When an application creates a file across a network, it is better to use GENERIC_READ | GENERIC_WRITE than to use /// GENERIC_WRITE alone. The resulting code is faster, because the redirector can use the cache manager and send fewer SMBs /// with more data. This combination also avoids an issue where writing to a file across a network can occasionally return ERROR_ACCESS_DENIED. /// /// File Streams /// On NTFS file systems, you can use /// CreateFileTransacted /// to create separate streams within a file. /// For more information, see File Streams. /// Directories /// An application cannot create a directory by using /// CreateFileTransacted /// , therefore only the /// OPEN_EXISTING /// value is valid for /// dwCreationDisposition /// for this use case. To create a directory, the application must call /// CreateDirectoryTransacted /// , /// CreateDirectory /// or /// CreateDirectoryEx /// . /// /// To open a directory using CreateFileTransacted, specify the FILE_FLAG_BACKUP_SEMANTICS flag as part of . /// Appropriate security checks still apply when this flag is used without SE_BACKUP_NAME and SE_RESTORE_NAME privileges. /// /// /// When using CreateFileTransacted to open a directory during defragmentation of a FAT or FAT32 file system volume, do not /// specify the MAXIMUM_ALLOWED access right. Access to the directory is denied if this is done. Specify the /// GENERIC_READ access right instead. /// /// For more information, see About Directory Management. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-createfiletransacteda HANDLE CreateFileTransactedA( LPCSTR // lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, // DWORD dwFlagsAndAttributes, HANDLE hTemplateFile, HANDLE hTransaction, PUSHORT pusMiniVersion, PVOID lpExtendedParameter ); [DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winbase.h", MSDNShortId = "0cbc081d-8787-409b-84bc-a6a28d8f83a0")] public static extern SafeHFILE CreateFileTransacted(string lpFileName, FileAccess dwDesiredAccess, FileShare dwShareMode, [Optional] SECURITY_ATTRIBUTES lpSecurityAttributes, FileMode dwCreationDisposition, FileFlagsAndAttributes dwFlagsAndAttributes, HFILE hTemplateFile, HTRXN hTransaction, in ushort pusMiniVersion, [Optional] IntPtr lpExtendedParameter); /// /// /// [Microsoft strongly recommends developers utilize alternative means to achieve your application’s needs. Many scenarios that TxF /// was developed for can be achieved through simpler and more readily available techniques. Furthermore, TxF may not be available in /// future versions of Microsoft Windows. For more information, and alternatives to TxF, please see /// /// Alternatives to using Transactional NTFS /// .] /// /// Creates or opens a file, file stream, or directory as a transacted operation. The function returns a handle that can be used to /// access the object. /// /// /// To perform this operation as a non-transacted operation or to access objects other than files (for example, named pipes, physical /// devices, mailslots), use the CreateFile function. /// /// For more information about transactions, see the Remarks section of this topic. /// /// /// The name of an object to be created or opened. /// The object must reside on the local computer; otherwise, the function fails and the last error code is set to ERROR_TRANSACTIONS_UNSUPPORTED_REMOTE. /// /// In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide /// characters, call the Unicode version of the function and prepend "\?" to the path. For more information, see Naming a File. For /// information on special device names, see Defining an MS-DOS Device Name. /// /// /// To create a file stream, specify the name of the file, a colon, and then the name of the stream. For more information, see File Streams. /// /// /// /// /// The access to the object, which can be summarized as read, write, both or neither (zero). The most commonly used values are /// GENERIC_READ, GENERIC_WRITE, or both ( GENERIC_READ | GENERIC_WRITE). For more information, see /// Generic Access Rights and File Security and Access Rights. /// /// /// If this parameter is zero, the application can query file, directory, or device attributes without accessing that file or device. /// For more information, see the Remarks section of this topic. /// /// /// You cannot request an access mode that conflicts with the sharing mode that is specified in an open request that has an open /// handle. For more information, see Creating and Opening Files. /// /// /// /// The sharing mode of an object, which can be read, write, both, delete, all of these, or none (refer to the following table). /// /// If this parameter is zero and CreateFileTransacted succeeds, the object cannot be shared and cannot be opened again until /// the handle is closed. For more information, see the Remarks section of this topic. /// /// /// You cannot request a sharing mode that conflicts with the access mode that is specified in an open request that has an open /// handle, because that would result in the following sharing violation: ERROR_SHARING_VIOLATION. For more information, see /// Creating and Opening Files. /// /// /// To enable a process to share an object while another process has the object open, use a combination of one or more of the /// following values to specify the access mode they can request to open the object. /// /// /// Note The sharing options for each open handle remain in effect until that handle is closed, regardless of process context. /// /// /// /// Value /// Meaning /// /// /// 0 0x00000000 /// Disables subsequent open operations on an object to request any type of access to that object. /// /// /// FILE_SHARE_DELETE 0x00000004 /// /// Enables subsequent open operations on an object to request delete access. Otherwise, other processes cannot open the object if /// they request delete access. If this flag is not specified, but the object has been opened for delete access, the function fails. /// /// /// /// FILE_SHARE_READ 0x00000001 /// /// Enables subsequent open operations on an object to request read access. Otherwise, other processes cannot open the object if they /// request read access. If this flag is not specified, but the object has been opened for read access, the function fails. /// /// /// /// FILE_SHARE_WRITE 0x00000002 /// /// Enables subsequent open operations on an object to request write access. Otherwise, other processes cannot open the object if /// they request write access. If this flag is not specified, but the object has been opened for write access or has a file mapping /// with write access, the function fails. /// /// /// /// /// /// /// A pointer to a SECURITY_ATTRIBUTES structure that contains an optional security descriptor and also determines whether or not the /// returned handle can be inherited by child processes. The parameter can be NULL. /// /// /// If the parameter is NULL, the handle returned by CreateFileTransacted cannot be inherited by any child processes /// your application may create and the object associated with the returned handle gets a default security descriptor. /// /// The bInheritHandle member of the structure specifies whether the returned handle can be inherited. /// /// The lpSecurityDescriptor member of the structure specifies a security descriptor for an object, but may also be NULL. /// /// /// If lpSecurityDescriptor member is NULL, the object associated with the returned handle is assigned a default /// security descriptor. /// /// /// CreateFileTransacted ignores the lpSecurityDescriptor member when opening an existing file, but continues to use /// the bInheritHandle member. /// /// For more information, see the Remarks section of this topic. /// /// /// An action to take on files that exist and do not exist. /// For more information, see the Remarks section of this topic. /// This parameter must be one of the following values, which cannot be combined. /// /// /// Value /// Meaning /// /// /// 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. For more information, see the Remarks section /// of this topic. /// /// /// /// 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 does not exist, the function fails and the last-error code is /// set to ERROR_FILE_NOT_FOUND (2). For more information, see the Remarks section of this topic. /// /// /// /// 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 the /// GENERIC_WRITE bit set as part of the parameter. /// /// /// /// /// /// The file attributes and flags, FILE_ATTRIBUTE_NORMAL being the most common default value. /// /// This parameter can include any combination of the available file attributes ( FILE_ATTRIBUTE_*). All other file attributes /// override FILE_ATTRIBUTE_NORMAL. /// /// /// This parameter can also contain combinations of flags ( FILE_FLAG_) for control of buffering behavior, access modes, and /// other special-purpose flags. These combine with any FILE_ATTRIBUTE_ values. /// /// /// This parameter can also contain Security Quality of Service (SQOS) information by specifying the SECURITY_SQOS_PRESENT /// flag. Additional SQOS-related flags information is presented in the table following the attributes and flags tables. /// /// /// Note When CreateFileTransacted opens an existing file, it generally combines the file flags with the file /// attributes of the existing file, and ignores any file attributes supplied as part of . Special cases are detailed in Creating and /// Opening Files. /// /// The following file attributes and flags are used only for file objects, not other types of objects that /// CreateFileTransacted /// /// opens (additional information can be found in the Remarks section of this topic). For more advanced access to file attributes, see /// /// SetFileAttributes /// . For a complete list of all file attributes with their values and descriptions, see /// File Attribute Constants /// . /// /// /// Attribute /// Meaning /// /// /// FILE_ATTRIBUTE_ARCHIVE 32 (0x20) /// The file should be archived. Applications use this attribute to mark files for backup or removal. /// /// /// FILE_ATTRIBUTE_ENCRYPTED 16384 (0x4000) /// /// 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 if FILE_ATTRIBUTE_SYSTEM is also specified. /// /// /// /// FILE_ATTRIBUTE_HIDDEN 2 (0x2) /// The file is hidden. Do not include it in an ordinary directory listing. /// /// /// FILE_ATTRIBUTE_NORMAL 128 (0x80) /// The file does not have other attributes set. This attribute is valid only if used alone. /// /// /// FILE_ATTRIBUTE_OFFLINE 4096 (0x1000) /// /// 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 (0x1) /// The file is read only. Applications can read the file, but cannot write to or delete it. /// /// /// FILE_ATTRIBUTE_SYSTEM 4 (0x4) /// The file is part of or used exclusively by an operating system. /// /// /// FILE_ATTRIBUTE_TEMPORARY 256 (0x100) /// /// The file is being used for temporary storage. File systems avoid writing data back to mass storage if sufficient cache memory is /// available, because an application deletes a temporary file after a handle is closed. In that case, the system can entirely avoid /// writing the data. Otherwise, the data is written after the handle is closed. /// /// /// /// /// /// Flag /// Meaning /// /// /// FILE_FLAG_BACKUP_SEMANTICS 0x02000000 /// /// The file is being opened or created for a backup or restore operation. The system ensures that the calling process overrides file /// security checks when the process has SE_BACKUP_NAME and SE_RESTORE_NAME privileges. For more information, see Changing Privileges /// in a Token. You must set this flag to obtain a handle to a directory. A directory handle can be passed to some functions instead /// of a file handle. For more information, see Directory Handles. /// /// /// /// FILE_FLAG_DELETE_ON_CLOSE 0x04000000 /// /// The file is to be deleted immediately after the last transacted writer handle to the file is closed, provided that the /// transaction is still active. If a file has been marked for deletion and a transacted writer handle is still open after the /// transaction completes, the file will not be deleted. If there are existing open handles to a file, the call fails unless they /// were all opened with the FILE_SHARE_DELETE share mode. Subsequent open requests for the file fail, unless the FILE_SHARE_DELETE /// share mode is specified. /// /// /// /// FILE_FLAG_NO_BUFFERING 0x20000000 /// /// The file is being opened with no system caching. This flag does not affect hard disk caching or memory mapped files. When /// combined with FILE_FLAG_OVERLAPPED, the flag gives maximum asynchronous performance, because the I/O does not rely on the /// synchronous operations of the memory manager. However, some I/O operations take more time, because data is not being held in the /// cache. Also, the file metadata may still be cached. To flush the metadata to disk, use the FlushFileBuffers function. An /// application must meet certain requirements when working with files that are opened with FILE_FLAG_NO_BUFFERING: One way to align /// buffers on integer multiples of the volume sector size is to use VirtualAlloc to allocate the buffers. It allocates memory that /// is aligned on addresses that are integer multiples of the operating system's memory page size. Because both memory page and /// volume sector sizes are powers of 2, this memory is also aligned on addresses that are integer multiples of a volume sector size. /// Memory pages are 4 or 8 KB in size; sectors are 512 bytes (hard disks), 2048 bytes (CD), or 4096 bytes (hard disks), and /// therefore, volume sectors can never be larger than memory pages. An application can determine a volume sector size by calling the /// GetDiskFreeSpace function. /// /// /// /// FILE_FLAG_OPEN_NO_RECALL 0x00100000 /// /// 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 0x00200000 /// /// Normal reparse point processing will not occur; CreateFileTransacted 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 the CREATE_ALWAYS flag. If the file is not a reparse point, then this flag is ignored. /// /// /// /// FILE_FLAG_OVERLAPPED 0x40000000 /// /// The file is being opened or created for asynchronous I/O. When the operation is complete, the event specified in the OVERLAPPED /// structure is set to the signaled state. Operations that take a significant amount of time to process return ERROR_IO_PENDING. If /// this flag is specified, the file can be used for simultaneous read and write operations. The system does not maintain the file /// pointer, therefore you must pass the file position to the read and write functions in the OVERLAPPED structure or update the file /// pointer. If this flag is not specified, then I/O operations are serialized, even if the calls to the read and write functions /// specify an OVERLAPPED structure. /// /// /// /// FILE_FLAG_POSIX_SEMANTICS 0x0100000 /// /// The file is to be accessed 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 0x10000000 /// The file is to be accessed randomly. The system can use this as a hint to optimize file caching. /// /// /// FILE_FLAG_SESSION_AWARE 0x00800000 /// /// 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 0x08000000 /// /// The file is to be accessed sequentially from beginning to end. The system can use this as a hint to optimize file caching. If an /// application moves the file pointer for random access, optimum caching may not occur. However, correct operation is still /// guaranteed. Specifying this flag can increase performance for applications that read large files using sequential access. /// Performance gains can be even more noticeable for applications that read large files mostly sequentially, but occasionally skip /// over small ranges of bytes. This flag has no effect if the file system does not support cached I/O and FILE_FLAG_NO_BUFFERING. /// /// /// /// FILE_FLAG_WRITE_THROUGH 0x80000000 /// /// Write operations will not go through any intermediate cache, they will go directly to disk. If FILE_FLAG_NO_BUFFERING is not also /// specified, so that system caching is in effect, then the data is written to the system cache, but is flushed to disk without /// delay. If FILE_FLAG_NO_BUFFERING is also specified, so that system caching is not in effect, then the data is immediately flushed /// to disk without going through the system cache. The operating system also requests a write-through the hard disk cache to /// persistent media. However, not all hardware supports this write-through capability. /// /// /// /// /// The parameter can also specify Security Quality of Service information. For more information, see Impersonation Levels. When the /// calling application specifies the SECURITY_SQOS_PRESENT flag as part of , it can also contain one or more of the following values. /// /// /// /// Security flag /// Meaning /// /// /// 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 the /// SECURITY_SQOS_PRESENT flag. /// /// /// /// /// /// /// A valid 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. This parameter can be NULL. /// /// When opening an existing file, CreateFileTransacted ignores the template file. /// When opening a new EFS-encrypted file, the file inherits the DACL from its parent directory. /// /// /// A handle to the transaction. This handle is returned by the CreateTransaction function. /// /// /// /// The miniversion to be opened. If the transaction specified in is not the transaction that is modifying the file, this parameter /// should be NULL. Otherwise, this parameter can be a miniversion identifier returned by the FSCTL_TXFS_CREATE_MINIVERSION /// control code, or one of the following values. /// /// /// /// Value /// Meaning /// /// /// TXFS_MINIVERSION_COMMITTED_VIEW 0x0000 /// The view of the file as of its last commit. /// /// /// TXFS_MINIVERSION_DIRTY_VIEW 0xFFFF /// The view of the file as it is being modified by the transaction. /// /// /// TXFS_MINIVERSION_DEFAULT_VIEW 0xFFFE /// /// Either the committed or dirty view of the file, depending on the context. A transaction that is modifying the file gets the dirty /// view, while a transaction that is not modifying the file gets the committed view. /// /// /// /// /// /// TBD /// /// /// If the function succeeds, the return value is an open handle to the specified file, device, named pipe, or mail slot. /// If the function fails, the return value is INVALID_HANDLE_VALUE. To get extended error information, call GetLastError. /// /// /// /// When using the handle returned by CreateFileTransacted, use the transacted version of file I/O functions instead of the /// standard file I/O functions where appropriate. For more information, see Programming Considerations for Transactional NTFS. /// /// /// When opening a transacted handle to a directory, that handle must have FILE_WRITE_DATA ( FILE_ADD_FILE) and /// FILE_APPEND_DATA ( FILE_ADD_SUBDIRECTORY) permissions. These are included in FILE_GENERIC_WRITE permissions. /// You should open directories with fewer permissions if you are just using the handle to create files or subdirectories; otherwise, /// sharing violations can occur. /// /// /// You cannot open a file with FILE_EXECUTE access level when that file is a part of another transaction (that is, another /// application opened it by calling CreateFileTransacted). This means that CreateFileTransacted fails if the access /// level FILE_EXECUTE or FILE_ALL_ACCESS is specified /// /// /// When a non-transacted application calls CreateFileTransacted with MAXIMUM_ALLOWED specified for , a handle is /// opened with the same access level every time. When a transacted application calls CreateFileTransacted with /// MAXIMUM_ALLOWED specified for , a handle is opened with a differing amount of access based on whether the file is locked /// by a transaction. For example, if the calling application has FILE_EXECUTE access level for a file, the application only /// obtains this access if the file that is being opened is either not locked by a transaction, or is locked by a transaction and the /// application is already a transacted reader for that file. /// /// See Transactional NTFS for a complete description of transacted operations. /// /// Use the CloseHandle function to close an object handle returned by CreateFileTransacted when the handle is no longer /// needed, and prior to committing or rolling back the transaction. /// /// /// Some file systems, such as the NTFS file system, support compression or encryption for individual files and directories. On /// volumes that are formatted for that kind of file system, a new file inherits the compression and encryption attributes of its directory. /// /// /// You cannot use CreateFileTransacted to control compression on a file or directory. For more information, see File /// Compression and Decompression, and File Encryption. /// /// Symbolic link behavior—If the call to this function creates a new file, there is no change in behavior. /// If FILE_FLAG_OPEN_REPARSE_POINT is specified: /// /// If an existing file is opened and it is a symbolic link, the handle returned is a handle to the symbolic link. /// If TRUNCATE_EXISTING or FILE_FLAG_DELETE_ON_CLOSE are specified, the file affected is a symbolic link. /// /// If /// FILE_FLAG_OPEN_REPARSE_POINT /// is not specified: /// /// If an existing file is opened and it is a symbolic link, the handle returned is a handle to the target. /// /// If CREATE_ALWAYS, TRUNCATE_EXISTING, or FILE_FLAG_DELETE_ON_CLOSE are specified, the file affected is the target. /// /// /// /// A multi-sector write is not guaranteed to be atomic unless you are using a transaction (that is, the handle created is a /// transacted handle). A single-sector write is atomic. Multi-sector writes that are cached may not always be written to the disk; /// therefore, specify /// /// FILE_FLAG_WRITE_THROUGH /// to ensure that an entire multi-sector write is written to the disk without caching. /// /// As stated previously, if the parameter is NULL, the handle returned by CreateFileTransacted cannot be inherited by /// any child processes your application may create. The following information regarding this parameter also applies: /// /// /// /// If bInheritHandle is not FALSE, which is any nonzero value, then the handle can be inherited. Therefore it is /// critical this structure member be properly initialized to FALSE if you do not intend the handle to be inheritable. /// /// /// The access control lists (ACL) in the default security descriptor for a file or directory are inherited from its parent directory. /// /// /// The target file system must support security on files and directories for the lpSecurityDescriptor to have an effect on /// them, which can be determined by using GetVolumeInformation /// /// /// In Windows 8 and Windows Server 2012, this function is supported by the following technologies. /// /// /// Technology /// Supported /// /// /// Server Message Block (SMB) 3.0 protocol /// No /// /// /// SMB 3.0 Transparent Failover (TFO) /// No /// /// /// SMB 3.0 with Scale-out File Shares (SO) /// No /// /// /// Cluster Shared Volume File System (CsvFS) /// No /// /// /// Resilient File System (ReFS) /// No /// /// /// Note that SMB 3.0 does not support TxF. /// Files /// /// If you try to create a file on a floppy drive that does not have a floppy disk or a CD-ROM drive that does not have a CD, the /// system displays a message for the user to insert a disk or a CD. To prevent the system from displaying this message, call the /// /// SetErrorMode /// function with /// SEM_FAILCRITICALERRORS /// . /// For more information, see Creating and Opening Files. /// /// If you rename or delete a file and then restore it shortly afterward, the system searches the cache for file information to /// restore. Cached information includes its short/long name pair and creation time. /// /// /// If you call CreateFileTransacted on a file that is pending deletion as a result of a previous call to DeleteFile, the /// function fails. The operating system delays file deletion until all handles to the file are closed. GetLastError returns ERROR_ACCESS_DENIED. /// /// /// The 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. See Obtaining and Setting File Information and GetFileInformationByHandle. /// /// /// When an application creates a file across a network, it is better to use GENERIC_READ | GENERIC_WRITE than to use /// GENERIC_WRITE alone. The resulting code is faster, because the redirector can use the cache manager and send fewer SMBs /// with more data. This combination also avoids an issue where writing to a file across a network can occasionally return ERROR_ACCESS_DENIED. /// /// File Streams /// On NTFS file systems, you can use /// CreateFileTransacted /// to create separate streams within a file. /// For more information, see File Streams. /// Directories /// An application cannot create a directory by using /// CreateFileTransacted /// , therefore only the /// OPEN_EXISTING /// value is valid for /// dwCreationDisposition /// for this use case. To create a directory, the application must call /// CreateDirectoryTransacted /// , /// CreateDirectory /// or /// CreateDirectoryEx /// . /// /// To open a directory using CreateFileTransacted, specify the FILE_FLAG_BACKUP_SEMANTICS flag as part of . /// Appropriate security checks still apply when this flag is used without SE_BACKUP_NAME and SE_RESTORE_NAME privileges. /// /// /// When using CreateFileTransacted to open a directory during defragmentation of a FAT or FAT32 file system volume, do not /// specify the MAXIMUM_ALLOWED access right. Access to the directory is denied if this is done. Specify the /// GENERIC_READ access right instead. /// /// For more information, see About Directory Management. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-createfiletransacteda HANDLE CreateFileTransactedA( LPCSTR // lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, // DWORD dwFlagsAndAttributes, HANDLE hTemplateFile, HANDLE hTransaction, PUSHORT pusMiniVersion, PVOID lpExtendedParameter ); [DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winbase.h", MSDNShortId = "0cbc081d-8787-409b-84bc-a6a28d8f83a0")] public static extern SafeHFILE CreateFileTransacted(string lpFileName, FileAccess dwDesiredAccess, FileShare dwShareMode, [Optional] SECURITY_ATTRIBUTES lpSecurityAttributes, FileMode dwCreationDisposition, FileFlagsAndAttributes dwFlagsAndAttributes, HFILE hTemplateFile, HTRXN hTransaction, [Optional] IntPtr pusMiniVersion, [Optional] IntPtr lpExtendedParameter); /// /// /// [Microsoft strongly recommends developers utilize alternative means to achieve your application’s needs. Many scenarios that TxF /// was developed for can be achieved through simpler and more readily available techniques. Furthermore, TxF may not be available in /// future versions of Microsoft Windows. For more information, and alternatives to TxF, please see /// /// Alternatives to using Transactional NTFS /// .] /// /// Establishes a hard link between an existing file and a new file as a transacted operation. This function is only supported on the /// NTFS file system, and only for files, not directories. /// /// /// /// The name of the new file. /// This parameter cannot specify the name of a directory. /// /// /// The name of the existing file. /// This parameter cannot specify the name of a directory. /// /// /// Reserved; must be NULL. /// /// /// A handle to the transaction. This handle is returned by the CreateTransaction function. /// /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero (0). To get extended error information, call GetLastError. /// /// The maximum number of hard links that can be created with this function is 1023 per file. If more than 1023 links are created for /// a file, an error results. /// /// The files must reside on the local computer; otherwise, the function fails and the last error code is set to ERROR_TRANSACTIONS_UNSUPPORTED_REMOTE. /// /// /// /// Any directory entry for a file that is created with CreateFileTransacted or CreateHardLinkTransacted is a hard link to an /// associated file. An additional hard link that is created with the CreateHardLinkTransacted function allows you to have /// multiple directory entries for a file, that is, multiple hard links to the same file, which can be different names in the same /// directory, or the same or different names in different directories. However, all hard links to a file must be on the same volume. /// /// /// Because hard links are only directory entries for a file, when an application modifies a file through any hard link, all /// applications that use any other hard link to the file see the changes. Also, all of the directory entries are updated if the file /// changes. For example, if a file size changes, all of the hard links to the file show the new file size. /// /// /// The security descriptor belongs to the file to which a hard link points. The link itself is only a directory entry, and does not /// have a security descriptor. Therefore, when you change the security descriptor of a hard link, you a change the security /// descriptor of the underlying file, and all hard links that point to the file allow the newly specified access. You cannot give a /// file different security descriptors on a per-hard-link basis. /// /// /// This function does not modify the security descriptor of the file to be linked to, even if security descriptor information is /// passed in the parameter. /// /// /// Use DeleteFileTransacted to delete hard links. You can delete them in any order regardless of the order in which they are created. /// /// /// Flags, attributes, access, and sharing that are specified in CreateFileTransacted operate on a per-file basis. That is, if you /// open a file that does not allow sharing, another application cannot share the file by creating a new hard link to the file. /// /// /// When you create a hard link on the NTFS file system, the file attribute information in the directory entry is refreshed only when /// the file is opened, or when GetFileInformationByHandle is called with the handle of a specific file. /// /// Symbolic links: If the path points to a symbolic link, the function creates a hard link to the target. /// In Windows 8 and Windows Server 2012, this function is supported by the following technologies. /// /// /// Technology /// Supported /// /// /// Server Message Block (SMB) 3.0 protocol /// No /// /// /// SMB 3.0 Transparent Failover (TFO) /// No /// /// /// SMB 3.0 with Scale-out File Shares (SO) /// No /// /// /// Cluster Shared Volume File System (CsvFS) /// No /// /// /// Resilient File System (ReFS) /// No /// /// /// Note that SMB 3.0 does not support TxF. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-createhardlinktransacteda BOOL CreateHardLinkTransactedA( // LPCSTR lpFileName, LPCSTR lpExistingFileName, LPSECURITY_ATTRIBUTES lpSecurityAttributes, HANDLE hTransaction ); [DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winbase.h", MSDNShortId = "27dd5b0a-08ef-4757-8f51-03d9918028c8")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool CreateHardLinkTransacted(string lpFileName, string lpExistingFileName, [Optional] SECURITY_ATTRIBUTES lpSecurityAttributes, HTRXN hTransaction); /// /// /// [Microsoft strongly recommends developers utilize alternative means to achieve your application’s needs. Many scenarios that TxF /// was developed for can be achieved through simpler and more readily available techniques. Furthermore, TxF may not be available in /// future versions of Microsoft Windows. For more information, and alternatives to TxF, please see Alternatives to using /// Transactional NTFS.] /// /// Deletes an existing file as a transacted operation. /// /// /// The name of the file to be deleted. /// /// In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide /// characters, call the Unicode version of the function and prepend "\?" to the path. For more information, see Naming a File. /// /// The file must reside on the local computer; otherwise, the function fails and the last error code is set to ERROR_TRANSACTIONS_UNSUPPORTED_REMOTE. /// /// /// A handle to the transaction. This handle is returned by the CreateTransaction function. /// /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is 0 (zero). To get extended error information, call GetLastError. /// /// /// /// If an application attempts to delete a file that does not exist, the DeleteFileTransacted function fails with /// ERROR_FILE_NOT_FOUND. If the file is a read-only file, the function fails with ERROR_ACCESS_DENIED. /// /// The following list identifies some tips for deleting, removing, or closing files: /// /// /// To delete a read-only file, first you must remove the read-only attribute. /// /// /// /// To delete or rename a file, you must have either delete permission on the file, or delete child permission in the parent directory. /// /// /// /// To recursively delete the files in a directory, use the SHFileOperation function. /// /// /// To remove an empty directory, use the RemoveDirectoryTransacted function. /// /// /// To close an open file, use the CloseHandle function. /// /// /// /// If you set up a directory with all access except delete and delete child, and the access control lists (ACL) of new files are /// inherited, then you can create a file without being able to delete it. However, then you can create a file, and then get all the /// access you request on the handle that is returned to you at the time you create the file. /// /// /// If you request delete permission at the time you create a file, you can delete or rename the file with that handle, but not with /// any other handle. For more information, see File Security and Access Rights. /// /// /// The DeleteFileTransacted function fails if an application attempts to delete a file that has other handles open for normal /// I/O or as a memory-mapped file ( FILE_SHARE_DELETE must have been specified when other handles were opened). /// /// /// The DeleteFileTransacted function marks a file for deletion on close. The file is deleted after the last transacted writer /// handle to the file is closed, provided that the transaction is still active. If a file has been marked for deletion and a /// transacted writer handle is still open after the transaction completes, the file will not be deleted. /// /// /// Symbolic links: If the path points to a symbolic link, the symbolic link is deleted, not the target. To delete a target, /// you must call CreateFile and specify FILE_FLAG_DELETE_ON_CLOSE. /// /// In Windows 8 and Windows Server 2012, this function is supported by the following technologies. /// /// /// Technology /// Supported /// /// /// Server Message Block (SMB) 3.0 protocol /// No /// /// /// SMB 3.0 Transparent Failover (TFO) /// No /// /// /// SMB 3.0 with Scale-out File Shares (SO) /// No /// /// /// Cluster Shared Volume File System (CsvFS) /// No /// /// /// Resilient File System (ReFS) /// No /// /// /// SMB 3.0 does not support TxF. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-deletefiletransacteda BOOL DeleteFileTransactedA( LPCSTR // lpFileName, HANDLE hTransaction ); [DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winbase.h", MSDNShortId = "e0a6230b-2da1-4746-95fe-80f7b6bae41f")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool DeleteFileTransacted(string lpFileName, HTRXN hTransaction); /// /// /// [Microsoft strongly recommends developers utilize alternative means to achieve your application’s needs. Many scenarios that TxF /// was developed for can be achieved through simpler and more readily available techniques. Furthermore, TxF may not be available in /// future versions of Microsoft Windows. For more information, and alternatives to TxF, please see Alternatives to using /// Transactional NTFS.] /// /// /// Creates an enumeration of all the hard links to the specified file as a transacted operation. The function returns a handle to /// the enumeration that can be used on subsequent calls to the FindNextFileNameW function. /// /// /// /// The name of the file. /// /// The file must reside on the local computer; otherwise, the function fails and the last error code is set to /// ERROR_TRANSACTIONS_UNSUPPORTED_REMOTE (6805). /// /// /// /// Reserved; specify zero (0). /// /// /// /// The size of the buffer pointed to by the LinkName parameter, in characters. If this call fails and the error is /// ERROR_MORE_DATA (234), the value that is returned by this parameter is the size that the buffer pointed to by LinkName /// must be to contain all the data. /// /// /// /// A pointer to a buffer to store the first link name found for lpFileName. /// /// /// A handle to the transaction. This handle is returned by the CreateTransaction function. /// /// /// /// If the function succeeds, the return value is a search handle that can be used with the FindNextFileNameW function or closed with /// the FindClose function. /// /// /// If the function fails, the return value is INVALID_HANDLE_VALUE (0xffffffff). To get extended error information, call the /// GetLastError function. /// /// /// /// In Windows 8 and Windows Server 2012, this function is supported by the following technologies. /// /// /// Technology /// Supported /// /// /// Server Message Block (SMB) 3.0 protocol /// No /// /// /// SMB 3.0 Transparent Failover (TFO) /// No /// /// /// SMB 3.0 with Scale-out File Shares (SO) /// No /// /// /// Cluster Shared Volume File System (CsvFS) /// No /// /// /// Resilient File System (ReFS) /// No /// /// /// SMB 3.0 does not support TxF. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-findfirstfilenametransactedw HANDLE // FindFirstFileNameTransactedW( LPCWSTR lpFileName, DWORD dwFlags, LPDWORD StringLength, PWSTR LinkName, HANDLE hTransaction ); [DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("winbase.h", MSDNShortId = "79c7d32d-3cb7-4e27-9db1-f24282bf606a")] public static extern SafeSearchHandle FindFirstFileNameTransactedW(string lpFileName, uint dwFlags, ref uint StringLength, StringBuilder LinkName, HTRXN hTransaction); /// /// /// [Microsoft strongly recommends developers utilize alternative means to achieve your application’s needs. Many scenarios that TxF /// was developed for can be achieved through simpler and more readily available techniques. Furthermore, TxF may not be available in /// future versions of Microsoft Windows. For more information, and alternatives to TxF, please see Alternatives to using /// Transactional NTFS.] /// /// Searches a directory for a file or subdirectory with a name that matches a specific name as a transacted operation. /// This function is the transacted form of the FindFirstFileEx function. /// For the most basic version of this function, see FindFirstFile. /// /// /// /// The directory or path, and the file name. The file name can include wildcard characters, for example, an asterisk (*) or a /// question mark (?). /// /// /// This parameter should not be NULL, an invalid string (for example, an empty string or a string that is missing the /// terminating null character), or end in a trailing backslash (). /// /// /// If the string ends with a wildcard, period (.), or directory name, the user must have access to the root and all subdirectories /// on the path. /// /// /// In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide /// characters, call the Unicode version of the function and prepend "\?" to the path. For more information, see Naming a File. /// /// The file must reside on the local computer; otherwise, the function fails and the last error code is set to ERROR_TRANSACTIONS_UNSUPPORTED_REMOTE. /// /// /// The information level of the returned data. /// This parameter is one of the FINDEX_INFO_LEVELS enumeration values. /// /// /// A pointer to the WIN32_FIND_DATA structure that receives information about a found file or subdirectory. /// /// /// The type of filtering to perform that is different from wildcard matching. /// This parameter is one of the FINDEX_SEARCH_OPS enumeration values. /// /// /// A pointer to the search criteria if the specified fSearchOp needs structured search information. /// /// At this time, none of the supported fSearchOp values require extended search information. Therefore, this pointer must be NULL. /// /// /// /// Specifies additional flags that control the search. /// /// /// Value /// Meaning /// /// /// FIND_FIRST_EX_CASE_SENSITIVE 1 /// Searches are case-sensitive. /// /// /// /// /// A handle to the transaction. This handle is returned by the CreateTransaction function. /// /// /// /// If the function succeeds, the return value is a search handle used in a subsequent call to FindNextFile or FindClose, and the /// lpFindFileData parameter contains information about the first file or directory found. /// /// /// If the function fails or fails to locate files from the search string in the lpFileName parameter, the return value is /// INVALID_HANDLE_VALUE and the contents of lpFindFileData are indeterminate. To get extended error information, call the /// GetLastError function. /// /// /// /// /// The FindFirstFileTransacted function opens a search handle and returns information about the first file that the file /// system finds with a name that matches the specified pattern. This may or may not be the first file or directory that appears in a /// directory-listing application (such as the dir command) when given the same file name string pattern. This is because /// FindFirstFileTransacted does no sorting of the search results. For additional information, see FindNextFile. /// /// The following list identifies some other search characteristics: /// /// /// The search is performed strictly on the name of the file, not on any attributes such as a date or a file type. /// /// /// The search includes the long and short file names. /// /// /// An attempt to open a search with a trailing backslash always fails. /// /// /// /// Passing an invalid string, NULL, or empty string for the lpFileName parameter is not a valid use of this function. Results /// in this case are undefined. /// /// /// /// /// Note In rare cases, file information on NTFS file systems may not be current at the time you call this function. To be /// assured of getting the current file information, call the GetFileInformationByHandle function. /// /// /// If the underlying file system does not support the specified type of filtering, other than directory filtering, /// FindFirstFileTransacted fails with the error ERROR_NOT_SUPPORTED. The application must use FINDEX_SEARCH_OPS type /// FileExSearchNameMatch and perform its own filtering. /// /// /// After the search handle is established, use it in the FindNextFile function to search for other files that match the same pattern /// with the same filtering that is being performed. When the search handle is not needed, it should be closed by using the FindClose function. /// /// /// As stated previously, you cannot use a trailing backslash () in the lpFileName input string for FindFirstFileTransacted, /// therefore it may not be obvious how to search root directories. If you want to see files or get the attributes of a root /// directory, the following options would apply: /// /// /// /// To examine files in a root directory, you can use "C:\*" and step through the directory by using FindNextFile. /// /// /// To get the attributes of a root directory, use the GetFileAttributes function. /// /// /// Note Prepending the string "\\?\" does not allow access to the root directory. /// /// On network shares, you can use an lpFileName in the form of the following: "\\server\service\*". However, you cannot use an /// lpFileName that points to the share itself; for example, "\\server\service" is not valid. /// /// /// To examine a directory that is not a root directory, use the path to that directory, without a trailing backslash. For example, /// an argument of "C:\Windows" returns information about the directory "C:\Windows", not about a directory or file in "C:\Windows". /// To examine the files and directories in "C:\Windows", use an lpFileName of "C:\Windows*". /// /// /// Be aware that some other thread or process could create or delete a file with this name between the time you query for the result /// and the time you act on the information. If this is a potential concern for your application, one possible solution is to use the /// CreateFile function with CREATE_NEW (which fails if the file exists) or OPEN_EXISTING (which fails if the file does /// not exist). /// /// /// If you are writing a 32-bit application to list all the files in a directory and the application may be run on a 64-bit computer, /// you should call Wow64DisableWow64FsRedirection before calling FindFirstFileTransacted and call /// Wow64RevertWow64FsRedirection after the last call to FindNextFile. For more information, see File System Redirector. /// /// /// If the path points to a symbolic link, the WIN32_FIND_DATA buffer contains information about the symbolic link, not the target. /// /// In Windows 8 and Windows Server 2012, this function is supported by the following technologies. /// /// /// Technology /// Supported /// /// /// Server Message Block (SMB) 3.0 protocol /// No /// /// /// SMB 3.0 Transparent Failover (TFO) /// No /// /// /// SMB 3.0 with Scale-out File Shares (SO) /// No /// /// /// Cluster Shared Volume File System (CsvFS) /// No /// /// /// Resilient File System (ReFS) /// No /// /// /// SMB 3.0 does not support TxF. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-findfirstfiletransacteda HANDLE FindFirstFileTransactedA( // LPCSTR lpFileName, FINDEX_INFO_LEVELS fInfoLevelId, LPVOID lpFindFileData, FINDEX_SEARCH_OPS fSearchOp, LPVOID lpSearchFilter, // DWORD dwAdditionalFlags, HANDLE hTransaction ); [DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winbase.h", MSDNShortId = "d94bf32b-f14b-44b4-824b-ed453d0424ef")] public static extern SafeSearchHandle FindFirstFileTransacted(string lpFileName, FINDEX_INFO_LEVELS fInfoLevelId, out WIN32_FIND_DATA lpFindFileData, FINDEX_SEARCH_OPS fSearchOp, [Optional] IntPtr lpSearchFilter, FIND_FIRST dwAdditionalFlags, HTRXN hTransaction); /// /// /// [Microsoft strongly recommends developers utilize alternative means to achieve your application’s needs. Many scenarios that TxF /// was developed for can be achieved through simpler and more readily available techniques. Furthermore, TxF may not be available in /// future versions of Microsoft Windows. For more information, and alternatives to TxF, please see Alternatives to using /// Transactional NTFS.] /// /// Enumerates the first stream in the specified file or directory as a transacted operation. /// /// /// The fully qualified file name. /// /// The file must reside on the local computer; otherwise, the function fails and the last error code is set to /// ERROR_TRANSACTIONS_UNSUPPORTED_REMOTE (6805). /// /// /// /// /// The information level of the returned data. This parameter is one of the values in the STREAM_INFO_LEVELS enumeration type. /// /// /// /// Value /// Meaning /// /// /// FindStreamInfoStandard 0 /// The data is returned in a WIN32_FIND_STREAM_DATA structure. /// /// /// /// /// A pointer to a buffer that receives the file data. The format of this data depends on the value of the InfoLevel parameter. /// /// /// Reserved for future use. This parameter must be zero. /// /// /// A handle to the transaction. This handle is returned by the CreateTransaction function. /// /// /// If the function succeeds, the return value is a search handle that can be used in subsequent calls to the FindNextStreamWfunction. /// If the function fails, the return value is INVALID_HANDLE_VALUE. To get extended error information, call GetLastError. /// /// /// /// All files contain a default data stream. On NTFS, files can also contain one or more named data streams. On FAT file systems, /// files cannot have more that the default data stream, and therefore, this function will not return valid results when used on FAT /// filesystem files. This function works on all file systems that supports hard links; otherwise, the function returns /// ERROR_STATUS_NOT_IMPLEMENTED (6805). /// /// /// The FindFirstStreamTransactedW function opens a search handle and returns information about the first stream in the /// specified file or directory. For files, this is always the default data stream, ::$DATA. After the search handle has been /// established, use it in the FindNextStreamW function to search for other streams in the specified file or directory. When the /// search handle is no longer needed, it should be closed using the FindClosefunction. /// /// In Windows 8 and Windows Server 2012, this function is supported by the following technologies. /// /// /// Technology /// Supported /// /// /// Server Message Block (SMB) 3.0 protocol /// No /// /// /// SMB 3.0 Transparent Failover (TFO) /// No /// /// /// SMB 3.0 with Scale-out File Shares (SO) /// No /// /// /// Cluster Shared Volume File System (CsvFS) /// No /// /// /// Resilient File System (ReFS) /// No /// /// /// SMB 3.0 does not support TxF. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-findfirststreamtransactedw HANDLE // FindFirstStreamTransactedW( LPCWSTR lpFileName, STREAM_INFO_LEVELS InfoLevel, LPVOID lpFindStreamData, DWORD dwFlags, HANDLE // hTransaction ); [DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("winbase.h", MSDNShortId = "76c64aa9-0501-457d-b774-c209fbac4ccc")] public static extern SafeSearchHandle FindFirstStreamTransactedW(string lpFileName, STREAM_INFO_LEVELS InfoLevel, out WIN32_FIND_STREAM_DATA lpFindStreamData, [Optional] uint dwFlags, HTRXN hTransaction); /// /// /// [Microsoft strongly recommends developers utilize alternative means to achieve your application’s needs. Many scenarios that TxF /// was developed for can be achieved through simpler and more readily available techniques. Furthermore, TxF may not be available in /// future versions of Microsoft Windows. For more information, and alternatives to TxF, please see Alternatives to using /// Transactional NTFS.] /// /// Retrieves file system attributes for a specified file or directory as a transacted operation. /// /// /// The name of the file or directory. /// /// In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide /// characters, call the Unicode version of the function and prepend "\?" to the path. For more information, see Naming a File. /// /// /// The file or directory must reside on the local computer; otherwise, the function fails and the last error code is set to ERROR_TRANSACTIONS_UNSUPPORTED_REMOTE. /// /// /// /// The level of attribute information to retrieve. /// This parameter can be the following value from the GET_FILEEX_INFO_LEVELS enumeration. /// /// /// Value /// Meaning /// /// /// GetFileExInfoStandard /// The lpFileInformation parameter is a WIN32_FILE_ATTRIBUTE_DATA structure. /// /// /// /// /// A pointer to a buffer that receives the attribute information. /// /// The type of attribute information that is stored into this buffer is determined by the value of fInfoLevelId. If the fInfoLevelId /// parameter is GetFileExInfoStandard then this parameter points to a WIN32_FILE_ATTRIBUTE_DATA structure /// /// /// /// A handle to the transaction. This handle is returned by the CreateTransaction function. /// /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero (0). To get extended error information, call GetLastError. /// /// /// /// When GetFileAttributesTransacted is called on a directory that is a mounted folder, it returns the attributes of the /// directory, not those of the root directory in the volume that the mounted folder associates with the directory. To obtain the /// file attributes of the associated volume, call GetVolumeNameForVolumeMountPoint to obtain the name of the associated volume. Then /// use the resulting name in a call to GetFileAttributesTransacted. The results are the attributes of the root directory on /// the associated volume. /// /// In Windows 8 and Windows Server 2012, this function is supported by the following technologies. /// /// /// Technology /// Supported /// /// /// Server Message Block (SMB) 3.0 protocol /// No /// /// /// SMB 3.0 Transparent Failover (TFO) /// No /// /// /// SMB 3.0 with Scale-out File Shares (SO) /// No /// /// /// Cluster Shared Volume File System (CsvFS) /// No /// /// /// Resilient File System (ReFS) /// No /// /// /// SMB 3.0 does not support TxF. /// Symbolic links: If the path points to a symbolic link, the function returns attributes for the symbolic link. /// Transacted Operations /// /// If a file is open for modification in a transaction, no other thread can open the file for modification until the transaction is /// committed. Conversely, if a file is open for modification outside of a transaction, no transacted thread can open the file for /// modification until the non-transacted handle is closed. If a non-transacted thread has a handle opened to modify a file, a call /// to GetFileAttributesTransacted for that file will fail with an ERROR_TRANSACTIONAL_CONFLICT error. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getfileattributestransacteda BOOL // GetFileAttributesTransactedA( LPCSTR lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId, LPVOID lpFileInformation, HANDLE // hTransaction ); [DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winbase.h", MSDNShortId = "dd1435da-93e5-440a-913a-9e40e39b4a01")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetFileAttributesTransacted(string lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation, HTRXN hTransaction); /// /// /// [Microsoft strongly recommends developers utilize alternative means to achieve your application’s needs. Many scenarios that TxF /// was developed for can be achieved through simpler and more readily available techniques. Furthermore, TxF may not be available in /// future versions of Microsoft Windows. For more information, and alternatives to TxF, please see Alternatives to using /// Transactional NTFS.] /// /// Retrieves the full path and file name of the specified file as a transacted operation. /// To perform this operation without transactions, use the GetFullPathName function. /// For more information about file and path names, see File Names, Paths, and Namespaces. /// /// /// The name of the file. /// This string can use short (the 8.3 form) or long file names. This string can be a share or volume name. /// The file must reside on the local computer; otherwise, the function fails and the last error code is set to ERROR_TRANSACTIONS_UNSUPPORTED_REMOTE. /// /// /// The size of the buffer to receive the null-terminated string for the drive and path, in TCHARs. /// /// /// A pointer to a buffer that receives the null-terminated string for the drive and path. /// /// /// /// A pointer to a buffer that receives the address (in lpBuffer) of the final file name component in the path. Specify NULL /// if you do not need to receive this information. /// /// If lpBuffer points to a directory and not a file, lpFilePart receives 0 (zero). /// /// /// A handle to the transaction. This handle is returned by the CreateTransaction function. /// /// /// /// If the function succeeds, the return value is the length, in TCHARs, of the string copied to lpBuffer, not including the /// terminating null character. /// /// /// If the lpBuffer buffer is too small to contain the path, the return value is the size, in TCHARs, of the buffer that is /// required to hold the path and the terminating null character. /// /// If the function fails for any other reason, the return value is zero. To get extended error information, call GetLastError. /// /// /// /// GetFullPathNameTransacted merges the name of the current drive and directory with a specified file name to determine the /// full path and file name of a specified file. It also calculates the address of the file name portion of the full path and file /// name. This function does not verify that the resulting path and file name are valid, or that they see an existing file on the /// associated volume. /// /// /// Share and volume names are valid input for lpFileName. For example, the following list identities the returned path and file /// names if test-2 is a remote computer and U: is a network mapped drive: /// /// /// /// If you specify "\\test-2\q$\lh" the path returned is "\\test-2\q$\lh" /// /// /// If you specify "\\?\UNC\test-2\q$\lh" the path returned is "\\?\UNC\test-2\q$\lh" /// /// /// If you specify "U:" the path returned is "U:\" /// /// /// /// GetFullPathNameTransacted does not convert the specified file name, lpFileName. If the specified file name exists, you can /// use GetLongPathNameTransacted, GetLongPathName, or GetShortPathName to convert to long or short path names, respectively. /// /// /// If the return value is greater than the value specified in nBufferLength, you can call the function again with a buffer that is /// large enough to hold the path. For an example of this case as well as using zero length buffer for dynamic allocation, see the /// Example Code section. /// /// /// Note Although the return value in this case is a length that includes the terminating null character, the return value on /// success does not include the terminating null character in the count. /// /// In Windows 8 and Windows Server 2012, this function is supported by the following technologies. /// /// /// Technology /// Supported /// /// /// Server Message Block (SMB) 3.0 protocol /// No /// /// /// SMB 3.0 Transparent Failover (TFO) /// No /// /// /// SMB 3.0 with Scale-out File Shares (SO) /// No /// /// /// Cluster Shared Volume File System (CsvFS) /// No /// /// /// Resilient File System (ReFS) /// No /// /// /// SMB 3.0 does not support TxF. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getfullpathnametransacteda DWORD // GetFullPathNameTransactedA( LPCSTR lpFileName, DWORD nBufferLength, LPSTR lpBuffer, LPSTR *lpFilePart, HANDLE hTransaction ); [DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winbase.h", MSDNShortId = "63cbcec6-e9f0-4db3-bf2f-03a987000af1")] public static extern uint GetFullPathNameTransacted(string lpFileName, uint nBufferLength, StringBuilder lpBuffer, out IntPtr lpFilePart, HTRXN hTransaction); /// /// /// [Microsoft strongly recommends developers utilize alternative means to achieve your application’s needs. Many scenarios that TxF /// was developed for can be achieved through simpler and more readily available techniques. Furthermore, TxF may not be available in /// future versions of Microsoft Windows. For more information, and alternatives to TxF, please see Alternatives to using /// Transactional NTFS.] /// /// Converts the specified path to its long form as a transacted operation. /// To perform this operation without a transaction, use the GetLongPathName function. /// For more information about file and path names, see Naming Files, Paths, and Namespaces. /// /// /// The path to be converted. /// /// In the ANSI version of this function, the name is limited to MAX_PATH (260) characters. To extend this limit to 32,767 /// wide characters, call the Unicode version of the function and prepend "\?" to the path. For more information, see Naming Files, /// Paths, and Namespaces. /// /// The path must reside on the local computer; otherwise, the function fails and the last error code is set to ERROR_TRANSACTIONS_UNSUPPORTED_REMOTE. /// /// /// A pointer to the buffer to receive the long path. /// You can use the same buffer you used for the lpszShortPath parameter. /// /// /// The size of the buffer lpszLongPath points to, in TCHAR s. /// /// /// A handle to the transaction. This handle is returned by the CreateTransaction function. /// /// /// /// If the function succeeds, the return value is the length, in TCHAR s, of the string copied to lpszLongPath, not including /// the terminating null character. /// /// /// If the lpBuffer buffer is too small to contain the path, the return value is the size, in TCHAR s, of the buffer that is /// required to hold the path and the terminating null character. /// /// /// If the function fails for any other reason, such as if the file does not exist, the return value is zero. To get extended error /// information, call GetLastError. /// /// /// /// On many file systems, a short file name contains a tilde () character. /// /// If a long path is not found, this function returns the name specified in the lpszShortPath parameter in the lpszLongPath parameter. /// /// /// If the return value is greater than the value specified in cchBuffer, you can call the function again with a buffer that is large /// enough to hold the path. For an example of this case, see the Example Code section for GetFullPathName. /// /// /// Note Although the return value in this case is a length that includes the terminating null character, the return value on /// success does not include the terminating null character in the count. /// /// /// It is possible to have access to a file or directory but not have access to some of the parent directories of that file or /// directory. As a result, GetLongPathNameTransacted may fail when it is unable to query the parent directory of a path /// component to determine the long name for that component. This check can be skipped for directory components that have file /// extensions longer than 3 characters, or total lengths longer than 12 characters. For more information, see the Short vs. Long /// Names section of Naming Files, Paths, and Namespaces. /// /// In Windows 8 and Windows Server 2012, this function is supported by the following technologies. /// /// /// Technology /// Supported /// /// /// Server Message Block (SMB) 3.0 protocol /// No /// /// /// SMB 3.0 Transparent Failover (TFO) /// No /// /// /// SMB 3.0 with Scale-out File Shares (SO) /// No /// /// /// Cluster Shared Volume File System (CsvFS) /// No /// /// /// Resilient File System (ReFS) /// No /// /// /// SMB 3.0 does not support TxF. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getlongpathnametransacteda DWORD // GetLongPathNameTransactedA( LPCSTR lpszShortPath, LPSTR lpszLongPath, DWORD cchBuffer, HANDLE hTransaction ); [DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winbase.h", MSDNShortId = "8523cde9-f0dd-4832-8d9d-9e68bac89344")] public static extern uint GetLongPathNameTransacted(string lpszShortPath, StringBuilder lpszLongPath, uint cchBuffer, HTRXN hTransaction); /// /// /// [Microsoft strongly recommends developers utilize alternative means to achieve your application’s needs. Many scenarios that TxF /// was developed for can be achieved through simpler and more readily available techniques. Furthermore, TxF may not be available in /// future versions of Microsoft Windows. For more information, and alternatives to TxF, please see Alternatives to using /// Transactional NTFS.] /// /// Moves an existing file or a directory, including its children, as a transacted operation. /// /// /// The current name of the existing file or directory on the local computer. /// /// In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide /// characters, call the Unicode version of the function and prepend "\?" to the path. For more information, see Naming a File. /// /// /// /// /// The new name for the file or directory. The new name must not already exist. A new file may be on a different file system or /// drive. A new directory must be on the same drive. /// /// /// In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide /// characters, call the Unicode version of the function and prepend "\?" to the path. For more information, see Naming a File. /// /// /// /// /// A pointer to a CopyProgressRoutine callback function that is called each time another portion of the file has been moved. The /// callback function can be useful if you provide a user interface that displays the progress of the operation. This parameter can /// be NULL. /// /// /// /// An argument to be passed to the CopyProgressRoutine callback function. This parameter can be NULL. /// /// /// The move options. This parameter can be one or more of the following values. /// /// /// Value /// Meaning /// /// /// MOVEFILE_COPY_ALLOWED 2 (0x2) /// /// If the file is to be moved to a different volume, the function simulates the move by using the CopyFile and DeleteFile functions. /// If the file is successfully copied to a different volume and the original file is unable to be deleted, the function succeeds /// leaving the source file intact. This value cannot be used with MOVEFILE_DELAY_UNTIL_REBOOT. /// /// /// /// MOVEFILE_CREATE_HARDLINK 16 (0x10) /// Reserved for future use. /// /// /// MOVEFILE_DELAY_UNTIL_REBOOT 4 (0x4) /// /// The system does not move the file until the operating system is restarted. The system moves the file immediately after AUTOCHK is /// executed, but before creating any paging files. Consequently, this parameter enables the function to delete paging files from /// previous startups. This value can only be used if the process is in the context of a user who belongs to the administrators group /// or the LocalSystem account. This value cannot be used with MOVEFILE_COPY_ALLOWED. The write operation to the registry value as /// detailed in the Remarks section is what is transacted. The file move is finished when the computer restarts, after the /// transaction is complete. /// /// /// /// MOVEFILE_REPLACE_EXISTING 1 (0x1) /// /// If a file named lpNewFileName exists, the function replaces its contents with the contents of the lpExistingFileName file. This /// value cannot be used if lpNewFileName or lpExistingFileName names a directory. /// /// /// /// MOVEFILE_WRITE_THROUGH 8 (0x8) /// /// A call to MoveFileTransacted means that the move file operation is complete when the commit operation is completed. This flag is /// unnecessary; there are no negative affects if this flag is specified, other than an operation slowdown. The function does not /// return until the file has actually been moved on the disk. Setting this value guarantees that a move performed as a copy and /// delete operation is flushed to disk before the function returns. The flush occurs at the end of the copy operation. This value /// has no effect if MOVEFILE_DELAY_UNTIL_REBOOT is set. /// /// /// /// /// /// A handle to the transaction. This handle is returned by the CreateTransaction function. /// /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// /// When moving a file across volumes, if lpProgressRoutine returns PROGRESS_CANCEL due to the user canceling the operation, /// MoveFileTransacted will return zero and GetLastError will return ERROR_REQUEST_ABORTED. The existing file is left intact. /// /// /// When moving a file across volumes, if lpProgressRoutine returns PROGRESS_STOP due to the user stopping the operation, /// MoveFileTransacted will return zero and GetLastError will return ERROR_REQUEST_ABORTED. The existing file is left intact. /// /// /// /// /// If the dwFlags parameter specifies MOVEFILE_DELAY_UNTIL_REBOOT, MoveFileTransacted fails if it cannot access the /// registry. The function transactionally stores the locations of the files to be renamed at restart in the following registry /// value: HKEY_LOCAL_MACHINE<b>SYSTEM<b>CurrentControlSet<b>Control<b>Session Manager<b>PendingFileRenameOperations /// /// /// This registry value is of type REG_MULTI_SZ. Each rename operation stores one of the following NULL-terminated /// strings, depending on whether the rename is a delete or not: /// /// szDstFile\0\0 /// szSrcFile\0szDstFile\0 /// The string szDstFile\0\0 indicates that the file szDstFile is to be deleted on reboot. /// The string szSrcFile\0szDstFile\0 indicates that szSrcFile is to be renamed szDstFile on reboot. /// /// Note Although \0\0 is technically not allowed in a REG_MULTI_SZ node, it can because the file is considered to be /// renamed to a null name. /// /// /// The system uses these registry entries to complete the operations at restart in the same order that they were issued. For more /// information about using the MOVEFILE_DELAY_UNTIL_REBOOT flag, see MoveFileWithProgress. /// /// /// If a file is moved across volumes, MoveFileTransacted does not move the security descriptor with the file. The file is /// assigned the default security descriptor in the destination directory. /// /// /// This function always fails if you specify the MOVEFILE_FAIL_IF_NOT_TRACKABLE flag; tracking is not supported by TxF. /// /// In Windows 8 and Windows Server 2012, this function is supported by the following technologies. /// /// /// Technology /// Supported /// /// /// Server Message Block (SMB) 3.0 protocol /// No /// /// /// SMB 3.0 Transparent Failover (TFO) /// No /// /// /// SMB 3.0 with Scale-out File Shares (SO) /// No /// /// /// Cluster Shared Volume File System (CsvFS) /// No /// /// /// Resilient File System (ReFS) /// No /// /// /// SMB 3.0 does not support TxF. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-movefiletransacteda BOOL MoveFileTransactedA( LPCSTR // lpExistingFileName, LPCSTR lpNewFileName, LPPROGRESS_ROUTINE lpProgressRoutine, LPVOID lpData, DWORD dwFlags, HANDLE hTransaction ); [DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winbase.h", MSDNShortId = "466d733b-30d2-4297-a0e6-77038f1a21d5")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool MoveFileTransacted(string lpExistingFileName, string lpNewFileName, CopyProgressRoutine lpProgressRoutine, [Optional] IntPtr lpData, MOVEFILE dwFlags, HTRXN hTransaction); /// /// /// [Microsoft strongly recommends developers utilize alternative means to achieve your application’s needs. Many scenarios that TxF /// was developed for can be achieved through simpler and more readily available techniques. Furthermore, TxF may not be available in /// future versions of Microsoft Windows. For more information, and alternatives to TxF, please see Alternatives to using /// Transactional NTFS.] /// /// Deletes an existing empty directory as a transacted operation. /// /// /// /// The path of the directory to be removed. The path must specify an empty directory, and the calling process must have delete /// access to the directory. /// /// /// In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide /// characters, call the Unicode version of the function and prepend "\?" to the path. For more information, see Naming a File. /// /// The directory must reside on the local computer; otherwise, the function fails and the last error code is set to ERROR_TRANSACTIONS_UNSUPPORTED_REMOTE. /// /// /// A handle to the transaction. This handle is returned by the CreateTransaction function. /// /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// /// /// /// The RemoveDirectoryTransacted function marks a directory for deletion on close. Therefore, the directory is not removed /// until the last handle to the directory is closed. /// /// /// RemoveDirectory removes a directory junction, even if the contents of the target are not empty; the function removes directory /// junctions regardless of the state of the target object. /// /// In Windows 8 and Windows Server 2012, this function is supported by the following technologies. /// /// /// Technology /// Supported /// /// /// Server Message Block (SMB) 3.0 protocol /// No /// /// /// SMB 3.0 Transparent Failover (TFO) /// No /// /// /// SMB 3.0 with Scale-out File Shares (SO) /// No /// /// /// Cluster Shared Volume File System (CsvFS) /// No /// /// /// Resilient File System (ReFS) /// No /// /// /// SMB 3.0 does not support TxF . /// // https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-removedirectorytransacteda BOOL // RemoveDirectoryTransactedA( LPCSTR lpPathName, HANDLE hTransaction ); [DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winbase.h", MSDNShortId = "e8600166-62dc-4398-9e16-43b07f7f0b89")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool RemoveDirectoryTransacted(string lpPathName, HTRXN hTransaction); /// /// /// [Microsoft strongly recommends developers utilize alternative means to achieve your application’s needs. Many scenarios that TxF /// was developed for can be achieved through simpler and more readily available techniques. Furthermore, TxF may not be available in /// future versions of Microsoft Windows. For more information, and alternatives to TxF, please see Alternatives to using /// Transactional NTFS.] /// /// Sets the attributes for a file or directory as a transacted operation. /// /// /// The name of the file whose attributes are to be set. /// /// In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide /// characters, call the Unicode version of the function and prepend "\?" to the path. For more information, see File Names, Paths, /// and Namespaces. /// /// The file must reside on the local computer; otherwise, the function fails and the last error code is set to ERROR_TRANSACTIONS_UNSUPPORTED_REMOTE. /// /// /// The file attributes to set for the file. /// /// For a list of file attribute value and their descriptions, see File Attribute Constants. This parameter can be one or more /// values, combined using the bitwise-OR operator. However, all other values override FILE_ATTRIBUTE_NORMAL. /// /// Not all attributes are supported by this function. For more information, see the Remarks section. /// The following is a list of supported attribute values. /// FILE_ATTRIBUTE_ARCHIVE (32 (0x20)) /// FILE_ATTRIBUTE_HIDDEN (2 (0x2)) /// FILE_ATTRIBUTE_NORMAL (128 (0x80)) /// FILE_ATTRIBUTE_NOT_CONTENT_INDEXED (8192 (0x2000)) /// FILE_ATTRIBUTE_OFFLINE (4096 (0x1000)) /// FILE_ATTRIBUTE_READONLY (1 (0x1)) /// FILE_ATTRIBUTE_SYSTEM (4 (0x4)) /// FILE_ATTRIBUTE_TEMPORARY (256 (0x100)) /// /// /// A handle to the transaction. This handle is returned by the CreateTransaction function. /// /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// /// /// /// The following table describes how to set the attributes that cannot be set using SetFileAttributesTransacted. Note that /// these are not transacted operations. /// /// /// /// Attribute /// How to Set /// /// /// FILE_ATTRIBUTE_COMPRESSED 0x800 /// To set a file's compression state, use the DeviceIoControl function with the FSCTL_SET_COMPRESSION operation. /// /// /// FILE_ATTRIBUTE_DEVICE 0x40 /// Reserved; do not use. /// /// /// FILE_ATTRIBUTE_DIRECTORY 0x10 /// Files cannot be converted into directories. To create a directory, use the CreateDirectory or CreateDirectoryEx function. /// /// /// FILE_ATTRIBUTE_ENCRYPTED 0x4000 /// /// To create an encrypted file, use the CreateFile function with the FILE_ATTRIBUTE_ENCRYPTED attribute. To convert an existing file /// into an encrypted file, use the EncryptFile function. /// /// /// /// FILE_ATTRIBUTE_REPARSE_POINT 0x400 /// /// To associate a reparse point with a file or directory, use the DeviceIoControl function with the FSCTL_SET_REPARSE_POINT operation. /// /// /// /// FILE_ATTRIBUTE_SPARSE_FILE 0x200 /// To set a file's sparse attribute, use the DeviceIoControl function with the FSCTL_SET_SPARSE operation. /// /// /// /// If a file is open for modification in a transaction, no other thread can successfully open the file for modification until the /// transaction is committed. If a transacted thread opens the file first, any subsequent threads that attempt to open the file for /// modification before the transaction is committed will receive a sharing violation. If a non-transacted thread opens the file for /// modification before the transacted thread does, and it is still open when the transacted thread attempts to open it, the /// transaction will receive the ERROR_TRANSACTIONAL_CONFLICT error. /// /// For more information on transactions, see Transactional NTFS. /// In Windows 8 and Windows Server 2012, this function is supported by the following technologies. /// /// /// Technology /// Supported /// /// /// Server Message Block (SMB) 3.0 protocol /// No /// /// /// SMB 3.0 Transparent Failover (TFO) /// No /// /// /// SMB 3.0 with Scale-out File Shares (SO) /// No /// /// /// Cluster Shared Volume File System (CsvFS) /// No /// /// /// Resilient File System (ReFS) /// No /// /// /// SMB 3.0 does not support TxF. /// Transacted Operations /// /// If a file is open for modification in a transaction, no other thread can open the file for modification until the transaction is /// committed. So if a transacted thread opens the file first, any subsequent threads that try modifying the file before the /// transaction is committed receives a sharing violation. If a non-transacted thread modifies the file before the transacted thread /// does, and the file is still open when the transaction attempts to open it, the transaction receives the error ERROR_TRANSACTIONAL_CONFLICT. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-setfileattributestransacteda BOOL // SetFileAttributesTransactedA( LPCSTR lpFileName, DWORD dwFileAttributes, HANDLE hTransaction ); [DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("winbase.h", MSDNShortId = "e25e77b2-a6ad-4ce4-8589-d7ff6c4074f6")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetFileAttributesTransacted(string lpFileName, FileFlagsAndAttributes dwFileAttributes, HTRXN hTransaction); /// Provides a handle to a transaction. [StructLayout(LayoutKind.Sequential)] public struct HTRXN : IKernelHandle { private IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public HTRXN(IntPtr preexistingHandle) => handle = preexistingHandle; /// Returns an invalid handle by instantiating a object with . public static HTRXN NULL => new HTRXN(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(HTRXN h) => h.handle; /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator HTRXN(IntPtr h) => new HTRXN(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(HTRXN h1, HTRXN h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(HTRXN h1, HTRXN h2) => h1.Equals(h2); /// public override bool Equals(object obj) => obj is HTRXN h ? handle == h.handle : false; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } } }