|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760 |
- /* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
- using Alphaleonis.Win32.Security;
- using Microsoft.Win32.SafeHandles;
- using System;
- using System.Diagnostics.CodeAnalysis;
- using System.IO;
- using System.Runtime.InteropServices;
- using System.Security;
- using System.Security.AccessControl;
- using System.Text;
-
- namespace Alphaleonis.Win32.Filesystem
- {
- internal static partial class NativeMethods
- {
- /// <summary>
- /// Copies an existing file to a new file, notifying the application of its progress through a callback function.
- /// </summary>
- /// <remarks>
- /// <para>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.</para>
- /// <para>This function preserves extended attributes, OLE structured storage, NTFS file system alternate data streams, security
- /// resource attributes, and file attributes.</para>
- /// <para>Windows 7, Windows Server 2008 R2, Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP:
- /// Security resource attributes (ATTRIBUTE_SECURITY_INFORMATION) for the existing file are not copied to the new file until
- /// Windows 8 and Windows Server 2012.</para>
- /// <para>Minimum supported client: Windows XP [desktop apps only]</para>
- /// <para>Minimum supported server: Windows Server 2003 [desktop apps only]</para>
- /// </remarks>
- /// <param name="lpExistingFileName">Filename of the existing file.</param>
- /// <param name="lpNewFileName">Filename of the new file.</param>
- /// <param name="lpProgressRoutine">The progress routine.</param>
- /// <param name="lpData">The data.</param>
- /// <param name="pbCancel">[out] The pb cancel.</param>
- /// <param name="dwCopyFlags">The copy flags.</param>
- /// <returns>
- /// <para>If the function succeeds, the return value is nonzero.</para>
- /// <para>If the function fails, the return value is zero. To get extended error information, call GetLastError.</para>
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "CopyFileExW"), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool CopyFileEx([MarshalAs(UnmanagedType.LPWStr)] string lpExistingFileName, [MarshalAs(UnmanagedType.LPWStr)] string lpNewFileName, NativeCopyMoveProgressRoutine lpProgressRoutine, IntPtr lpData, [MarshalAs(UnmanagedType.Bool)] out bool pbCancel, CopyOptions dwCopyFlags);
-
- /// <summary>
- /// Copies an existing file to a new file as a transacted operation, notifying the application of its progress through a callback
- /// function.
- /// </summary>
- /// <remarks>
- /// <para>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.</para>
- /// <para>This function preserves extended attributes, OLE structured storage, NTFS file system alternate data streams, security
- /// resource attributes, and file attributes.</para>
- /// <para>Windows 7, Windows Server 2008 R2, Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP:
- /// Security resource attributes (ATTRIBUTE_SECURITY_INFORMATION) for the existing file are not copied to the new file until
- /// Windows 8 and Windows Server 2012.</para>
- /// <para>Minimum supported client: Windows Vista [desktop apps only]</para>
- /// <para>Minimum supported server: Windows Server 2008 [desktop apps only]</para>
- /// </remarks>
- /// <returns>
- /// <para>If the function succeeds, the return value is nonzero.</para>
- /// <para>If the function fails, the return value is zero. To get extended error information, call GetLastError.</para>
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "CopyFileTransactedW"), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool CopyFileTransacted([MarshalAs(UnmanagedType.LPWStr)] string lpExistingFileName, [MarshalAs(UnmanagedType.LPWStr)] string lpNewFileName, NativeCopyMoveProgressRoutine lpProgressRoutine, IntPtr lpData, [MarshalAs(UnmanagedType.Bool)] out bool pbCancel, CopyOptions dwCopyFlags, SafeHandle hTransaction);
-
- /// <summary>
- /// Creates or opens a file or I/O device. The most commonly used I/O devices are as follows: file, file stream, directory, physical
- /// disk, volume, console buffer, tape drive, communications resource, mailslot, and pipe.
- /// </summary>
- /// <remarks>Minimum supported client: Windows XP.</remarks>
- /// <remarks>Minimum supported server: Windows Server 2003.</remarks>
- /// <returns>
- /// 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 Win32Errors.ERROR_INVALID_HANDLE. To get extended error information, call GetLastError.
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "CreateFileW"), SuppressUnmanagedCodeSecurity]
- internal static extern SafeFileHandle CreateFile([MarshalAs(UnmanagedType.LPWStr)] string lpFileName, [MarshalAs(UnmanagedType.U4)] FileSystemRights dwDesiredAccess, [MarshalAs(UnmanagedType.U4)] FileShare dwShareMode, [MarshalAs(UnmanagedType.LPStruct)] Security.NativeMethods.SecurityAttributes lpSecurityAttributes, [MarshalAs(UnmanagedType.U4)] FileMode dwCreationDisposition, [MarshalAs(UnmanagedType.U4)] ExtendedFileAttributes dwFlagsAndAttributes, IntPtr hTemplateFile);
-
- /// <summary>
- /// Creates or opens a file or I/O device. The most commonly used I/O devices are as follows: file, file stream, directory, physical
- /// disk, volume, console buffer, tape drive, communications resource, mailslot, and pipe.
- /// </summary>
- /// <remarks>Minimum supported client: Windows Vista [desktop apps only].</remarks>
- /// <remarks>Minimum supported server: Windows Server 2008 [desktop apps only].</remarks>
- /// <returns>
- /// 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 Win32Errors.ERROR_INVALID_HANDLE". To get extended error information, call GetLastError.
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "CreateFileTransactedW"), SuppressUnmanagedCodeSecurity]
- internal static extern SafeFileHandle CreateFileTransacted([MarshalAs(UnmanagedType.LPWStr)] string lpFileName, [MarshalAs(UnmanagedType.U4)] FileSystemRights dwDesiredAccess, [MarshalAs(UnmanagedType.U4)] FileShare dwShareMode, [MarshalAs(UnmanagedType.LPStruct)] Security.NativeMethods.SecurityAttributes lpSecurityAttributes, [MarshalAs(UnmanagedType.U4)] FileMode dwCreationDisposition, [MarshalAs(UnmanagedType.U4)] ExtendedFileAttributes dwFlagsAndAttributes, IntPtr hTemplateFile, SafeHandle hTransaction, IntPtr pusMiniVersion, IntPtr pExtendedParameter);
-
- /// <summary>Creates or opens a named or unnamed file mapping object for a specified file.</summary>
- /// <remarks>Minimum supported client: Windows XP.</remarks>
- /// <remarks>Minimum supported server: Windows Server 2003.</remarks>
- /// <returns>
- /// If the function succeeds, the return value is a handle to the newly created file mapping object. If the function fails, the return
- /// value is <see langword="null"/>.
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = false, CharSet = CharSet.Unicode, EntryPoint = "CreateFileMappingW"), SuppressUnmanagedCodeSecurity]
- internal static extern SafeFileHandle CreateFileMapping(SafeFileHandle hFile, SafeHandle lpSecurityAttributes, [MarshalAs(UnmanagedType.U4)] uint flProtect, [MarshalAs(UnmanagedType.U4)] uint dwMaximumSizeHigh, [MarshalAs(UnmanagedType.U4)] uint dwMaximumSizeLow, [MarshalAs(UnmanagedType.LPWStr)] string lpName);
-
- /// <summary>
- /// Establishes a hard link between an existing file and a new file. This function is only supported on the NTFS file system, and only
- /// for files, not directories.
- /// </summary>
- /// <remarks>Minimum supported client: Windows XP [desktop apps only].</remarks>
- /// <remarks>Minimum supported server: Windows Server 2003 [desktop apps only].</remarks>
- /// <returns>
- /// 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.
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "CreateHardLinkW"), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool CreateHardLink([MarshalAs(UnmanagedType.LPWStr)] string lpFileName, [MarshalAs(UnmanagedType.LPWStr)] string lpExistingFileName, IntPtr lpSecurityAttributes);
-
- /// <summary>
- /// 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.
- /// </summary>
- /// <remarks>Minimum supported client: Windows Vista [desktop apps only].</remarks>
- /// <remarks>Minimum supported server: Windows Server 2008 [desktop apps only].</remarks>
- /// <returns>
- /// 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.
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "CreateHardLinkTransactedW"), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool CreateHardLinkTransacted([MarshalAs(UnmanagedType.LPWStr)] string lpFileName, [MarshalAs(UnmanagedType.LPWStr)] string lpExistingFileName, IntPtr lpSecurityAttributes, SafeHandle hTransaction);
-
- /// <summary>Creates a symbolic link.</summary>
- /// <remarks>Minimum supported client: Windows Vista [desktop apps only].</remarks>
- /// <remarks>Minimum supported server: Windows Server 2008 [desktop apps only].</remarks>
- /// <remarks>
- /// The unmanaged prototype contains a return directive because the CreateSymbolicLink API function returns BOOLEAN, a one-byte data type.
- /// The default marshaling for bool is four bytes (to allow seamless integration with BOOL return values).
- /// If you were to use the default marshaling for BOOLEAN values, it's likely that you will get erroneous results.
- /// The return directive forces PInvoke to marshal just one byte of the return value.
- /// Source: http://www.informit.com/guides/content.aspx?g=dotnet&seqNum=762&ns=16196
- /// </remarks>
- /// <returns>
- /// 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.
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "CreateSymbolicLinkW"), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.I1)]
- internal static extern bool CreateSymbolicLink([MarshalAs(UnmanagedType.LPWStr)] string lpSymlinkFileName, [MarshalAs(UnmanagedType.LPWStr)] string lpTargetFileName, [MarshalAs(UnmanagedType.U4)] SymbolicLinkTarget dwFlags);
-
- /// <summary>Creates a symbolic link as a transacted operation.</summary>
- /// <remarks>Minimum supported client: Windows Vista [desktop apps only].</remarks>
- /// <remarks>Minimum supported server: Windows Server 2008 [desktop apps only].</remarks>
- /// <remarks>
- /// The unmanaged prototype contains a return directive because the CreateSymbolicLink API function returns BOOLEAN, a one-byte data type.
- /// The default marshaling for bool is four bytes (to allow seamless integration with BOOL return values).
- /// If you were to use the default marshaling for BOOLEAN values, it's likely that you will get erroneous results.
- /// The return directive forces PInvoke to marshal just one byte of the return value.
- /// Source: http://www.informit.com/guides/content.aspx?g=dotnet&seqNum=762&ns=16196
- /// </remarks>
- /// <returns>
- /// 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.
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "CreateSymbolicLinkTransactedW"), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.I1)]
- internal static extern bool CreateSymbolicLinkTransacted([MarshalAs(UnmanagedType.LPWStr)] string lpSymlinkFileName, [MarshalAs(UnmanagedType.LPWStr)] string lpTargetFileName, [MarshalAs(UnmanagedType.U4)] SymbolicLinkTarget dwFlags, SafeHandle hTransaction);
-
- /// <summary>Decrypts an encrypted file or directory.</summary>
- /// <remarks>
- /// The DecryptFile function requires exclusive access to the file being decrypted, and will fail if another process is using the file.
- /// If the file is not encrypted, DecryptFile simply returns a nonzero value, which indicates success. If lpFileName specifies a read-
- /// only file, the function fails and GetLastError returns ERROR_FILE_READ_ONLY. If lpFileName specifies a directory that contains a
- /// read-only file, the functions succeeds but the directory is not decrypted.
- /// </remarks>
- /// <remarks>Minimum supported client: Windows XP.</remarks>
- /// <remarks>Minimum supported server: Windows Server 2003.</remarks>
- /// <returns>
- /// 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.
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "DecryptFileW"), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool DecryptFile([MarshalAs(UnmanagedType.LPWStr)] string lpFileName, [MarshalAs(UnmanagedType.U4)] uint dwReserved);
-
- /// <summary>Deletes an existing file.</summary>
- /// <remarks>
- /// If an application attempts to delete a file that does not exist, the DeleteFile function fails with ERROR_FILE_NOT_FOUND.
- /// </remarks>
- /// <remarks>If the file is a read-only file, the function fails with ERROR_ACCESS_DENIED.</remarks>
- /// <remarks>
- /// 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.
- /// </remarks>
- /// <remarks>Minimum supported client: Windows XP [desktop apps | Windows Store apps].</remarks>
- /// <remarks>Minimum supported server: Windows Server 2003 [desktop apps | Windows Store apps].</remarks>
- /// <returns>
- /// 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.
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "DeleteFileW"), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool DeleteFile([MarshalAs(UnmanagedType.LPWStr)] string lpFileName);
-
- /// <summary>Deletes an existing file as a transacted operation.</summary>
- /// <remarks>Minimum supported client: Windows Vista [desktop apps only].</remarks>
- /// <remarks>Minimum supported server: Windows Server 2008 [desktop apps only].</remarks>
- /// <returns>
- /// 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.
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "DeleteFileTransactedW"), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool DeleteFileTransacted([MarshalAs(UnmanagedType.LPWStr)] string lpFileName, SafeHandle hTransaction);
-
- /// <summary>
- /// Encrypts a file or directory. All data streams in a file are encrypted. All new files created in an encrypted directory are
- /// encrypted.
- /// </summary>
- /// <remarks>
- /// The EncryptFile function requires exclusive access to the file being encrypted, and will fail if another process is using the file.
- /// If the file is already encrypted, EncryptFile simply returns a nonzero value, which indicates success. If the file is compressed,
- /// EncryptFile will decompress the file before encrypting it. If lpFileName specifies a read-only file, the function fails and
- /// GetLastError returns ERROR_FILE_READ_ONLY. If lpFileName specifies a directory that contains a read-only file, the functions
- /// succeeds but the directory is not encrypted.
- /// </remarks>
- /// <remarks>Minimum supported client: Windows XP.</remarks>
- /// <remarks>Minimum supported server: Windows Server 2003.</remarks>
- /// <returns>
- /// 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.
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "EncryptFileW"), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool EncryptFile([MarshalAs(UnmanagedType.LPWStr)] string lpFileName);
-
- /// <summary>
- /// Disables or enables encryption of the specified directory and the files in it. It does not affect encryption of subdirectories
- /// below the indicated directory.
- /// </summary>
- /// <remarks>
- /// EncryptionDisable() disables encryption of directories and files. It does not affect the visibility of files with the
- /// FILE_ATTRIBUTE_SYSTEM attribute set. This method will create/change the file "Desktop.ini" and wil set Encryption value:
- /// "Disable=0|1".
- /// </remarks>
- /// <remarks>Minimum supported client: Windows XP Professional [desktop apps only].</remarks>
- /// <remarks>Minimum supported server: Windows Server 2003 [desktop apps only].</remarks>
- /// <returns>
- /// 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.
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule"), SuppressUnmanagedCodeSecurity]
- [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool EncryptionDisable([MarshalAs(UnmanagedType.LPWStr)] string dirPath, [MarshalAs(UnmanagedType.Bool)] bool disable);
-
- /// <summary>Retrieves the encryption status of the specified file.</summary>
- /// <remarks>Minimum supported client: Windows XP Professional [desktop apps only].</remarks>
- /// <remarks>Minimum supported server: Windows Server 2003 [desktop apps only].</remarks>
- /// <returns>
- /// 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.
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "FileEncryptionStatusW"), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool FileEncryptionStatus([MarshalAs(UnmanagedType.LPWStr)] string lpFileName, out FileEncryptionStatus lpStatus);
-
- /// <summary>
- /// Closes a file search handle opened by the FindFirstFile, FindFirstFileEx, FindFirstFileNameW, FindFirstFileNameTransactedW,
- /// FindFirstFileTransacted, FindFirstStreamTransactedW, or FindFirstStreamW functions.
- /// </summary>
- /// <remarks>Minimum supported client: Windows XP [desktop apps | Windows Store apps].</remarks>
- /// <remarks>Minimum supported server: Windows Server 2003 [desktop apps | Windows Store apps].</remarks>
- /// <returns>
- /// 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.
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule"), SuppressUnmanagedCodeSecurity]
- [DllImport("kernel32.dll", SetLastError = false, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool FindClose(IntPtr hFindFile);
-
- /// <summary>Searches a directory for a file or subdirectory with a name and attributes that match those specified.</summary>
- /// <remarks>A trailing backslash is not allowed and will be removed.</remarks>
- /// <remarks>Minimum supported client: Windows XP [desktop apps | Windows Store apps].</remarks>
- /// <remarks>Minimum supported server: Windows Server 2003 [desktop apps | Windows Store apps].</remarks>
- /// <returns>
- /// 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.
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "FindFirstFileExW"), SuppressUnmanagedCodeSecurity]
- internal static extern SafeFindFileHandle FindFirstFileEx([MarshalAs(UnmanagedType.LPWStr)] string lpFileName, FINDEX_INFO_LEVELS fInfoLevelId, out WIN32_FIND_DATA lpFindFileData, FINDEX_SEARCH_OPS fSearchOp, IntPtr lpSearchFilter, FindExAdditionalFlags dwAdditionalFlags);
-
- /// <summary>
- /// Searches a directory for a file or subdirectory with a name that matches a specific name as a transacted operation.
- /// </summary>
- /// <remarks>A trailing backslash is not allowed and will be removed.</remarks>
- /// <remarks>Minimum supported client: Windows Vista [desktop apps only].</remarks>
- /// <remarks>Minimum supported server: Windows Server 2008 [desktop apps only].</remarks>
- /// <returns>
- /// 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.
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "FindFirstFileTransactedW"), SuppressUnmanagedCodeSecurity]
- internal static extern SafeFindFileHandle FindFirstFileTransacted([MarshalAs(UnmanagedType.LPWStr)] string lpFileName, FINDEX_INFO_LEVELS fInfoLevelId, out WIN32_FIND_DATA lpFindFileData, FINDEX_SEARCH_OPS fSearchOp, IntPtr lpSearchFilter, FindExAdditionalFlags dwAdditionalFlags, SafeHandle hTransaction);
-
- /// <summary>
- /// Creates an enumeration of all the hard links to the specified file. The FindFirstFileNameW function returns a handle to the
- /// enumeration that can be used on subsequent calls to the FindNextFileNameW function.
- /// </summary>
- /// <remarks>Minimum supported client: Windows Vista [desktop apps only].</remarks>
- /// <remarks>Minimum supported server: Windows Server 2008 [desktop apps only].</remarks>
- /// <returns>
- /// 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.
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "FindFirstFileNameW"), SuppressUnmanagedCodeSecurity]
- internal static extern SafeFindFileHandle FindFirstFileName([MarshalAs(UnmanagedType.LPWStr)] string lpFileName, [MarshalAs(UnmanagedType.U4)] uint dwFlags, [MarshalAs(UnmanagedType.U4)] out uint stringLength, StringBuilder linkName);
-
- /// <summary>
- /// 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.
- /// </summary>
- /// <remarks>Minimum supported client: Windows Vista [desktop apps only].</remarks>
- /// <remarks>Minimum supported server: Windows Server 2008 [desktop apps only].</remarks>
- /// <returns>
- /// 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.
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "FindFirstFileNameTransactedW"), SuppressUnmanagedCodeSecurity]
- internal static extern SafeFindFileHandle FindFirstFileNameTransacted([MarshalAs(UnmanagedType.LPWStr)] string lpFileName, [MarshalAs(UnmanagedType.U4)] uint dwFlags, [MarshalAs(UnmanagedType.U4)] out uint stringLength, StringBuilder linkName, SafeHandle hTransaction);
-
- /// <summary>
- /// Continues a file search from a previous call to the FindFirstFile, FindFirstFileEx, or FindFirstFileTransacted functions.
- /// </summary>
- /// <remarks>Minimum supported client: Windows XP [desktop apps | Windows Store apps].</remarks>
- /// <remarks>Minimum supported server: Windows Server 2003 [desktop apps | Windows Store apps].</remarks>
- /// <returns>
- /// If the function succeeds, the return value is nonzero and the lpFindFileData parameter contains information about the next file or
- /// directory found. If the function fails, the return value is zero and the contents of lpFindFileData are indeterminate. To get
- /// extended error information, call the GetLastError function. If the function fails because no more matching files can be found, the
- /// GetLastError function returns ERROR_NO_MORE_FILES.
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "FindNextFileW"), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool FindNextFile(SafeFindFileHandle hFindFile, out WIN32_FIND_DATA lpFindFileData);
-
- /// <summary>
- /// Continues enumerating the hard links to a file using the handle returned by a successful call to the FindFirstFileName function.
- /// </summary>
- /// <remarks>Minimum supported client: Windows Vista [desktop apps only].</remarks>
- /// <remarks>Minimum supported server: Windows Server 2008 [desktop apps only].</remarks>
- /// <returns>
- /// 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. If no matching files can be found, the GetLastError function returns ERROR_HANDLE_EOF.
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "FindNextFileNameW"), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool FindNextFileName(SafeFindFileHandle hFindStream, [MarshalAs(UnmanagedType.U4)] out uint stringLength, StringBuilder linkName);
-
- /// <summary>Flushes the buffers of a specified file and causes all buffered data to be written to a file.</summary>
- /// <remarks>Minimum supported client: Windows XP [desktop apps | Windows Store apps].</remarks>
- /// <remarks>Minimum supported server: Windows Server 2003 [desktop apps | Windows Store apps].</remarks>
- /// <returns>
- /// 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.
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool FlushFileBuffers(SafeFileHandle hFile);
-
- /// <summary>Retrieves the actual number of bytes of disk storage used to store a specified file.</summary>
- /// <remarks>Minimum supported client: Windows XP [desktop apps only].</remarks>
- /// <remarks>Minimum supported server: Windows Server 2003 [desktop apps only].</remarks>
- /// <returns>
- /// If the function succeeds, the return value is the low-order DWORD of the actual number of bytes of disk storage used to store the
- /// specified file, and if lpFileSizeHigh is non-NULL, the function puts the high-order DWORD of that actual value into the DWORD
- /// pointed to by that parameter. This is the compressed file size for compressed files, the actual file size for noncompressed files.
- /// If the function fails, and lpFileSizeHigh is NULL, the return value is INVALID_FILE_SIZE. To get extended error information, call
- /// GetLastError. If the return value is INVALID_FILE_SIZE and lpFileSizeHigh is non-NULL, an application must call GetLastError to
- /// determine whether the function has succeeded (value is NO_ERROR) or failed (value is other than NO_ERROR).
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "GetCompressedFileSizeW"), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.U4)]
- internal static extern uint GetCompressedFileSize([MarshalAs(UnmanagedType.LPWStr)] string lpFileName, [MarshalAs(UnmanagedType.U4)] out uint lpFileSizeHigh);
-
- /// <summary>Retrieves the actual number of bytes of disk storage used to store a specified file as a transacted operation.</summary>
- /// <remarks>Minimum supported client: Windows Vista [desktop apps only].</remarks>
- /// <remarks>Minimum supported server: Windows Server 2008 [desktop apps only].</remarks>
- /// <returns>
- /// If the function succeeds, the return value is the low-order DWORD of the actual number of bytes of disk storage used to store the
- /// specified file, and if lpFileSizeHigh is non-NULL, the function puts the high-order DWORD of that actual value into the DWORD
- /// pointed to by that parameter. This is the compressed file size for compressed files, the actual file size for noncompressed files.
- /// If the function fails, and lpFileSizeHigh is NULL, the return value is INVALID_FILE_SIZE. To get extended error information, call
- /// GetLastError. If the return value is INVALID_FILE_SIZE and lpFileSizeHigh is non-NULL, an application must call GetLastError to
- /// determine whether the function has succeeded (value is NO_ERROR) or failed (value is other than NO_ERROR).
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "GetCompressedFileSizeTransactedW"), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.U4)]
- internal static extern uint GetCompressedFileSizeTransacted([MarshalAs(UnmanagedType.LPWStr)] string lpFileName, [MarshalAs(UnmanagedType.U4)] out uint lpFileSizeHigh, SafeHandle hTransaction);
-
- /// <summary>
- /// Retrieves attributes for a specified file or directory.
- /// </summary>
- /// <remarks>
- /// <para>The GetFileAttributes function retrieves file system attribute information.</para>
- /// <para>GetFileAttributesEx can obtain other sets of file or directory attribute information.</para>
- /// <para>Currently, GetFileAttributesEx retrieves a set of standard attributes that is a superset of the file system attribute
- /// information.
- /// When the GetFileAttributesEx function 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 attributes of
- /// the associated volume, call GetVolumeNameForVolumeMountPoint to obtain the name of the associated volume. Then use the resulting
- /// name in a call to GetFileAttributesEx. The results are the attributes of the root directory on the associated volume.</para>
- /// <para>Symbolic link behavior: If the path points to a symbolic link, the function returns attributes for the symbolic link.</para>
- /// <para>Minimum supported client: Windows XP [desktop apps only]</para>
- /// <para>Minimum supported server: Windows Server 2003 [desktop apps only]</para>
- /// </remarks>
- /// <returns>
- /// <para>If the function succeeds, the return value is nonzero.</para>
- /// <para>If the function fails, the return value is zero. To get extended error information, call GetLastError.</para>
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "GetFileAttributesExW"), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool GetFileAttributesEx([MarshalAs(UnmanagedType.LPWStr)] string lpFileName, [MarshalAs(UnmanagedType.U4)] GetFileExInfoLevels fInfoLevelId, out WIN32_FILE_ATTRIBUTE_DATA lpFileInformation);
-
- /// <summary>Retrieves attributes for a specified file or directory.</summary>
- /// <remarks>
- /// <para>The GetFileAttributes function retrieves file system attribute information.</para>
- /// <para>GetFileAttributesEx can obtain other sets of file or directory attribute information.</para>
- /// <para>
- /// Currently, GetFileAttributesEx retrieves a set of standard attributes that is a superset of the file system attribute information.
- /// When the GetFileAttributesEx function 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 attributes of
- /// the associated volume, call GetVolumeNameForVolumeMountPoint to obtain the name of the associated volume. Then use the resulting
- /// name in a call to GetFileAttributesEx. The results are the attributes of the root directory on the associated volume.</para>
- /// <para>Symbolic link behavior: If the path points to a symbolic link, the function returns attributes for the symbolic link.</para>
- /// <para>Transacted Operations</para>
- /// <para>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.</para>
- /// <para>Minimum supported client: Windows Vista [desktop apps only]</para>
- /// <para>Minimum supported server: Windows Server 2008 [desktop apps only]</para>
- /// </remarks>
- /// <returns>
- /// <para>If the function succeeds, the return value is nonzero.</para>
- /// <para>If the function fails, the return value is zero. To get extended error information, call GetLastError.</para>
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "GetFileAttributesTransactedW"), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool GetFileAttributesTransacted([MarshalAs(UnmanagedType.LPWStr)] string lpFileName, [MarshalAs(UnmanagedType.U4)] GetFileExInfoLevels fInfoLevelId, out WIN32_FILE_ATTRIBUTE_DATA lpFileInformation, SafeHandle hTransaction);
-
- /// <summary>Retrieves file information for the specified file.</summary>
- /// <returns>
- /// If the function succeeds, the return value is nonzero and file information data is contained in the buffer pointed to by the lpByHandleFileInformation parameter.
- /// If the function fails, the return value is zero. To get extended error information, call GetLastError.
- /// </returns>
- /// <remarks>
- /// Depending on the underlying network features of the operating system and the type of server connected to,
- /// the GetFileInformationByHandle function may fail, return partial information, or full information for the given file.
- /// </remarks>
- /// <remarks>Minimum supported client: Windows XP [desktop apps only]</remarks>
- /// <remarks>Minimum supported server: Windows Server 2003 [desktop apps only]</remarks>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool GetFileInformationByHandle(SafeFileHandle hFile, [MarshalAs(UnmanagedType.Struct)] out BY_HANDLE_FILE_INFORMATION lpByHandleFileInformation);
-
- /// <summary>
- /// Retrieves file information for the specified file.
- /// </summary>
- /// <remarks>
- /// <para>Minimum supported client: Windows Vista [desktop apps | Windows Store apps]</para>
- /// <para>Minimum supported server: Windows Server 2008 [desktop apps | Windows Store apps]</para>
- /// <para>Redistributable: Windows SDK on Windows Server 2003 and Windows XP.</para>
- /// </remarks>
- /// <param name="hFile">The file.</param>
- /// <param name="fileInfoByHandleClass">The file information by handle class.</param>
- /// <param name="lpFileInformation">Information describing the file.</param>
- /// <param name="dwBufferSize">Size of the buffer.</param>
- /// <returns>
- /// <para>If the function succeeds, the return value is nonzero and file information data is contained in the buffer pointed to by the
- /// lpByHandleFileInformation parameter.</para>
- /// <para>If the function fails, the return value is zero. To get extended error information, call GetLastError.</para>
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool GetFileInformationByHandleEx(SafeFileHandle hFile, [MarshalAs(UnmanagedType.I4)] FileInfoByHandleClass fileInfoByHandleClass, SafeGlobalMemoryBufferHandle lpFileInformation, [MarshalAs(UnmanagedType.U4)] uint dwBufferSize);
-
- /// <summary>Retrieves file information for the specified file.</summary>
- /// <remarks>
- /// <para>Minimum supported client: Windows Vista [desktop apps | Windows Store apps]</para>
- /// <para>Minimum supported server: Windows Server 2008 [desktop apps | Windows Store apps]</para>
- /// <para>Redistributable: Windows SDK on Windows Server 2003 and Windows XP.</para>
- /// </remarks>
- /// <returns>
- /// <para>If the function succeeds, the return value is nonzero and file information data is contained in the buffer pointed to by the
- /// lpByHandleFileInformation parameter.</para>
- /// <para>If the function fails, the return value is zero. To get extended error information, call GetLastError.</para>
- /// </returns>
- /// <param name="hFile">The file.</param>
- /// <param name="fileInfoByHandleClass">The file information by handle class.</param>
- /// <param name="lpFileInformation">Information describing the file.</param>
- /// <param name="dwBufferSize">Size of the buffer.</param>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "GetFileInformationByHandleEx"), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool GetFileInformationByHandleEx_FileBasicInfo(SafeFileHandle hFile, [MarshalAs(UnmanagedType.I4)] FileInfoByHandleClass fileInfoByHandleClass, [MarshalAs(UnmanagedType.Struct)] out FILE_BASIC_INFO lpFileInformation, [MarshalAs(UnmanagedType.U4)] uint dwBufferSize);
-
- /// <summary>
- /// Retrieves the size of the specified file.
- /// </summary>
- /// <remarks>
- /// <para>Minimum supported client: Windows XP [desktop apps only]</para>
- /// <para>Minimum supported server: Windows Server 2003 [desktop apps only]</para>
- /// </remarks>
- /// <returns>
- /// <para>If the function succeeds, the return value is nonzero.</para>
- /// <para>If the function fails, the return value is zero. To get extended error information, call GetLastError.</para>
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool GetFileSizeEx(SafeFileHandle hFile, out long lpFileSize);
-
- /// <summary>Retrieves the final path for the specified file.</summary>
- /// <remarks>Minimum supported client: Windows Vista [desktop apps only].</remarks>
- /// <remarks>Minimum supported server: Windows Server 2008 [desktop apps only].</remarks>
- /// <returns>
- /// 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.
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "GetFinalPathNameByHandleW"), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.U4)]
- internal static extern uint GetFinalPathNameByHandle(SafeFileHandle hFile, StringBuilder lpszFilePath, [MarshalAs(UnmanagedType.U4)] uint cchFilePath, FinalPathFormats dwFlags);
-
- /// <summary>
- /// Checks whether the specified address is within a memory-mapped file in the address space of the specified process. If so, the
- /// function returns the name of the memory-mapped file.
- /// </summary>
- /// <remarks>Minimum supported client: Windows XP.</remarks>
- /// <remarks>Minimum supported server: Windows Server 2003.</remarks>
- /// <returns>
- /// 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.
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("psapi.dll", SetLastError = false, CharSet = CharSet.Unicode, EntryPoint = "GetMappedFileNameW"), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool GetMappedFileName(IntPtr hProcess, SafeLocalMemoryBufferHandle lpv, StringBuilder lpFilename, [MarshalAs(UnmanagedType.U4)] uint nSize);
-
- /// <summary>Locks the specified file for exclusive access by the calling process.</summary>
- /// <remarks>Minimum supported client: Windows XP.</remarks>
- /// <remarks>Minimum supported server: Windows Server 2003.</remarks>
- /// <returns>
- /// If the function succeeds, the return value is nonzero (TRUE). If the function fails, the return value is zero (FALSE). To get
- /// extended error information, call GetLastError.
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool LockFile(SafeFileHandle hFile, [MarshalAs(UnmanagedType.U4)] uint dwFileOffsetLow, [MarshalAs(UnmanagedType.U4)] uint dwFileOffsetHigh, [MarshalAs(UnmanagedType.U4)] uint nNumberOfBytesToLockLow, [MarshalAs(UnmanagedType.U4)] uint nNumberOfBytesToLockHigh);
-
- /// <summary>Maps a view of a file mapping into the address space of a calling process.</summary>
- /// <remarks>Minimum supported client: Windows XP.</remarks>
- /// <remarks>Minimum supported server: Windows Server 2003.</remarks>
- /// <returns>
- /// If the function succeeds, the return value is the starting address of the mapped view. If the function fails, the return value is
- /// <see langword="null"/>.
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = false, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
- internal static extern SafeLocalMemoryBufferHandle MapViewOfFile(SafeFileHandle hFileMappingObject, [MarshalAs(UnmanagedType.U4)] uint dwDesiredAccess, [MarshalAs(UnmanagedType.U4)] uint dwFileOffsetHigh, [MarshalAs(UnmanagedType.U4)] uint dwFileOffsetLow, UIntPtr dwNumberOfBytesToMap);
-
- /// <summary>
- /// Moves a file or directory, including its children.
- /// <para>You can provide a callback function that receives progress notifications.</para>
- /// </summary>
- /// <remarks>
- /// <para>The MoveFileWithProgress function coordinates its operation with the link tracking service, so link sources can be tracked as they are moved.</para>
- /// <para>Minimum supported client: Windows XP [desktop apps only]</para>
- /// <para>Minimum supported server: Windows Server 2003 [desktop apps only]</para>
- /// </remarks>
- /// <param name="lpExistingFileName">Filename of the existing file.</param>
- /// <param name="lpNewFileName">Filename of the new file.</param>
- /// <param name="lpProgressRoutine">The progress routine.</param>
- /// <param name="lpData">The data.</param>
- /// <param name="dwFlags">The flags.</param>
- /// <returns>
- /// <para>If the function succeeds, the return value is nonzero.</para>
- /// <para>If the function fails, the return value is zero. To get extended error information, call GetLastError.</para>
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "MoveFileWithProgressW"), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool MoveFileWithProgress([MarshalAs(UnmanagedType.LPWStr)] string lpExistingFileName, [MarshalAs(UnmanagedType.LPWStr)] string lpNewFileName, NativeCopyMoveProgressRoutine lpProgressRoutine, IntPtr lpData, [MarshalAs(UnmanagedType.U4)] MoveOptions dwFlags);
-
- /// <summary>
- /// Moves an existing file or a directory, including its children, as a transacted operation.
- /// <para>You can provide a callback function that receives progress notifications.</para>
- /// </summary>
- /// <remarks>
- /// <para>Minimum supported client: Windows Vista [desktop apps only]</para>
- /// <para>Minimum supported server: Windows Server 2008 [desktop apps only]</para>
- /// </remarks>
- /// <returns>
- /// <para>If the function succeeds, the return value is nonzero.</para>
- /// <para>If the function fails, the return value is zero. To get extended error information, call GetLastError.</para>
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "MoveFileTransactedW"), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool MoveFileTransacted([MarshalAs(UnmanagedType.LPWStr)] string lpExistingFileName, [MarshalAs(UnmanagedType.LPWStr)] string lpNewFileName, NativeCopyMoveProgressRoutine lpProgressRoutine, IntPtr lpData, [MarshalAs(UnmanagedType.U4)] MoveOptions dwCopyFlags, SafeHandle hTransaction);
-
- /// <summary>An application-defined callback function used with the CopyFileEx, MoveFileTransacted, and MoveFileWithProgress functions.
- /// <para>It is called when a portion of a copy or move operation is completed.</para>
- /// <para>The LPPROGRESS_ROUTINE type defines a pointer to this callback function.</para>
- /// <para>NativeCopyMoveProgressRoutine (NativeCopyMoveProgressRoutine) is a placeholder for the application-defined function name.</para>
- /// </summary>
- [SuppressUnmanagedCodeSecurity]
- internal delegate CopyMoveProgressResult NativeCopyMoveProgressRoutine(long totalFileSize, long totalBytesTransferred, long streamSize, long streamBytesTransferred, [MarshalAs(UnmanagedType.U4)] int dwStreamNumber, CopyMoveProgressCallbackReason dwCallbackReason, IntPtr hSourceFile, IntPtr hDestinationFile, IntPtr lpData);
-
- /// <summary>Replaces one file with another file, with the option of creating a backup copy of the original file. The replacement file assumes the name of the replaced file and its identity.</summary>
- /// <returns>
- /// 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.
- /// </returns>
- /// <remarks>Minimum supported client: Windows XP [desktop apps only]</remarks>
- /// <remarks>Minimum supported server: Windows Server 2003 [desktop apps only]</remarks>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "ReplaceFileW"), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool ReplaceFile([MarshalAs(UnmanagedType.LPWStr)] string lpReplacedFileName, [MarshalAs(UnmanagedType.LPWStr)] string lpReplacementFileName, [MarshalAs(UnmanagedType.LPWStr)] string lpBackupFileName, FileSystemRights dwReplaceFlags, IntPtr lpExclude, IntPtr lpReserved);
-
- /// <summary>Sets the attributes for a file or directory.</summary>
- /// <returns>
- /// 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.
- /// </returns>
- /// <remarks>Minimum supported client: Windows XP</remarks>
- /// <remarks>Minimum supported server: Windows Server 2003</remarks>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [SuppressMessage("Microsoft.Usage", "CA2205:UseManagedEquivalentsOfWin32Api")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "SetFileAttributesW"), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool SetFileAttributes([MarshalAs(UnmanagedType.LPWStr)] string lpFileName, [MarshalAs(UnmanagedType.U4)] FileAttributes dwFileAttributes);
-
- /// <summary>Sets the attributes for a file or directory as a transacted operation.</summary>
- /// <returns>
- /// 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.
- /// </returns>
- /// <remarks>Minimum supported client: Windows Vista [desktop apps only]</remarks>
- /// <remarks>Minimum supported server: Windows Server 2008 [desktop apps only]</remarks>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "SetFileAttributesTransactedW"), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool SetFileAttributesTransacted([MarshalAs(UnmanagedType.LPWStr)] string lpFileName, [MarshalAs(UnmanagedType.U4)] FileAttributes dwFileAttributes, SafeHandle hTransaction);
-
- /// <summary>Sets the date and time that the specified file or directory was created, last accessed, or last modified.</summary>
- /// <returns>
- /// 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.
- /// </returns>
- /// <remarks>Minimum supported client: Windows XP [desktop apps only]</remarks>
- /// <remarks>Minimum supported server: Windows Server 2003 [desktop apps only]</remarks>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool SetFileTime(SafeFileHandle hFile, SafeGlobalMemoryBufferHandle lpCreationTime, SafeGlobalMemoryBufferHandle lpLastAccessTime, SafeGlobalMemoryBufferHandle lpLastWriteTime);
-
- /// <summary>Unlocks a region in an open file. Unlocking a region enables other processes to access the region.</summary>
- /// <returns>
- /// 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.
- /// </returns>
- /// <remarks>Minimum supported client: Windows XP</remarks>
- /// <remarks>Minimum supported server: Windows Server 2003</remarks>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool UnlockFile(SafeFileHandle hFile, [MarshalAs(UnmanagedType.U4)] uint dwFileOffsetLow, [MarshalAs(UnmanagedType.U4)] uint dwFileOffsetHigh, [MarshalAs(UnmanagedType.U4)] uint nNumberOfBytesToUnlockLow, [MarshalAs(UnmanagedType.U4)] uint nNumberOfBytesToUnlockHigh);
-
- /// <summary>Unmaps a mapped view of a file from the calling process's address space.</summary>
- /// <remarks>Minimum supported client: Windows XP.</remarks>
- /// <remarks>Minimum supported server: Windows Server 2003.</remarks>
- /// <param name="lpBaseAddress">The base address.</param>
- /// <returns>
- /// 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.
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = false, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool UnmapViewOfFile(SafeLocalMemoryBufferHandle lpBaseAddress);
-
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
- internal static extern SafeFindFileHandle FindFirstStreamTransactedW(string fileName, STREAM_INFO_LEVELS infoLevel, SafeGlobalMemoryBufferHandle lpFindStreamData, int flags, SafeHandle hTransaction);
-
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
- internal static extern SafeFindFileHandle FindFirstStreamW(string fileName, STREAM_INFO_LEVELS infoLevel, SafeGlobalMemoryBufferHandle lpFindStreamData, int flags);
-
- [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool FindNextStreamW(SafeFindFileHandle handle, SafeGlobalMemoryBufferHandle lpFindStreamData);
- }
- }
|