网站首页  词典首页

请输入您要查询的函数:

 

术语 setfileinformationbyhandle
释义 SetFileInformationByHandle
语法:
C++
BOOL WINAPI SetFileInformationByHandle(
__in HANDLE hFile,
__in FILE_INFO_BY_HANDLE_CLASS FileInformationClass,
__in LPVOID lpFileInformation,
__in DWORD dwBufferSize
);
SetFileInformationByHandle功能
设置指定文件的文件资料。
要检索文件中的信息使用的文件句柄,见GetFileInformationByHandle或GetFileInformationByHandleEx。
参数
hFile [in]
A handle to the file for which to change information.
这种处理必须与所请求的变化适当的权限打开。有关详细信息,请参见备注和示例代码部分。
这种处理不应该是一个管道句柄。
FileInformationClass [in]
阿FILE_INFO_BY_HANDLE_CLASS枚举值,指定类型的信息进行更改。
要获取有效值的表,请参见备注部分。
lpFileInformation [in]
来一个缓冲区,它包含的信息更改指定文件的信息类的指针。的结构,这对应的是FileInformationClass指定的类参数点。
对于一个有效的结构类型的表,请参见备注部分。
dwBufferSize [in]
在lpFileInformation大小,以字节。
返回值
如果成功则返回非零或否则为0。
为了获得更多错误信息,调用GetLastError。
备注
某些文件信息略有不同类的行为在不同的操作系统版本。这些类支持的基本驱动程序,并返回任何信息,他们随时可能更改操作系统版本之间。
下表显示了使用这一功能的有效文件的信息类及其相应的数据结构类型。
FileInformationClass valuelpFileInformation类型
FileBasicInfoFILE_BASIC_INFO
FileRenameInfoFILE_RENAME_INFO
FileDispositionInfoFILE_DISPOSITION_INFO
FileAllocationInfoFILE_ALLOCATION_INFO
FileEndOfFileInfoFILE_END_OF_FILE_INFO
FileIoPriorityHintInfoFILE_IO_PRIORITY_HINT_INFO
您必须指定适当的访问标志在创建的文件句柄与SetFileInformationByHandle使用。例如,如果应用程序使用设置为true的DeleteFile成员FILE_DISPOSITION_INFO,该文件需要在删除访问呼吁要求CreateFile函数。要看到这样的例子,请参阅示例代码部分。有关文件权限的详细信息,请参阅文件安全性和访问权限。
如果有一定的处理,然后将所做的更改为信息类交易FileBasicInfo交易,FileRenameInfo,FileAllocationInfo,FileEndOfFileInfo和FileDispositionInfo。如果FileDispositionInfo指定,只有删除操作,如果交易要求的DeleteFile行动。在这种情况下,如果交易没有处理之前,关闭承诺,将其删除后不会发生。欲了解更多有关TxF的信息,请参阅交互式NTFS(TxF的)。
实例
下面的C + +示例演示如何创建一个文件并标记为删除处理时,它已关闭。
//...
HANDLE hFile = CreateFile (TEXT("tempfile"),
GENERIC_READ | GENERIC_WRITE | DELETE,
0 /* exclusive access */,
NULL, CREATE_ALWAYS,
0, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
FILE_DISPOSITION_INFO fdi;
fdi.DeleteFile = TRUE; // marking for deletion
BOOL fResult = SetFileInformationByHandle(
hFile,
FileDispositionInfo,
&fdi,
sizeof(FILE_DISPOSITION_INFO)
);

if (fResult)
{
// File will be deleted upon CloseHandle.
_tprintf(
TEXT("SetFileInformationByHandle marked tempfile for deletion\\n"));

// ...
// Now use the file for whatever temp data storage you need,
// it will automatically be deleted upon CloseHandle or
// application termination.
// ...
}
else
{
_tprintf(
TEXT("error %lu: SetFileInformationByHandle could not mark tempfile for deletion\\n"),
GetLastError());
}

CloseHandle(hFile);

// At this point, the file is closed and deleted by the system.
}
else
{
_tprintf(
TEXT("error %lu: could not create tempfile\\n"),
GetLastError());
}
//...

要求:
client最低支持Vista
server最低支持 Windows Server 2008
RedistributableWindows SDK的在Windows Server 2003和Windows XP。
HeaderWinBase.h(头文件:winuser.h),在Windows Server 2003和Windows XP的FileExtd.h
LibraryKernel32.lib,在Windows Server 2003和Windows XP的FileExtd.lib
DLLKernel32.dll
参见
CreateFile
文件管理函数
文件安全性和访问权限
通用访问权限
GetFileInformationByHandle
GetFileInformationByHandleEx
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年9月3日
==英文原文==SetFileInformationByHandle Function
Sets the file information for the specified file.
To retrieve file information using a file handle, see GetFileInformationByHandle or GetFileInformationByHandleEx .
Syntax
C++
BOOL WINAPI SetFileInformationByHandle(
__in HANDLE hFile,
__in FILE_INFO_BY_HANDLE_CLASS FileInformationClass,
__in LPVOID lpFileInformation,
__in DWORD dwBufferSize
);
Parameters
hFile [in]
A handle to the file for which to change information.
This handle must be opened with the appropriate permissions for the requested change. For more information, see the Remarks and Example Code sections.
This handle should not be a pipe handle.
FileInformationClass [in]
A FILE_INFO_BY_HANDLE_CLASS enumeration value that specifies the type of information to be changed.
For a table of valid values, see the Remarks section.
lpFileInformation [in]
A pointer to the buffer that contains the information to change for the specified file information class. The structure that this parameter points to corresponds to the class that is specified by FileInformationClass.
For a table of valid structure types, see the Remarks section.
dwBufferSize [in]
The size of lpFileInformation, in bytes.
Return Value
Returns nonzero if successful or zero otherwise.
To get extended error information, call GetLastError .
Remarks
Certain file information classes behave slightly differently on different operating system releases. These classes are supported by the underlying drivers, and any information they return is subject to change between operating system releases.
The following table shows the valid file information classes and their corresponding data structure types for use with this function.
FileInformationClass valuelpFileInformation type
FileBasicInfoFILE_BASIC_INFO
FileRenameInfoFILE_RENAME_INFO
FileDispositionInfoFILE_DISPOSITION_INFO
FileAllocationInfoFILE_ALLOCATION_INFO
FileEndOfFileInfoFILE_END_OF_FILE_INFO
FileIoPriorityHintInfoFILE_IO_PRIORITY_HINT_INFO

You must specify appropriate access flags when creating the file handle for use with SetFileInformationByHandle. For example, if the application is using FILE_DISPOSITION_INFO with the DeleteFile member set to true, the file would need DELETE access requested in the call to the CreateFile function. To see an example of this, see the Example Code section. For more information about file permissions, see File Security and Access Rights .
If there is a transaction bound to the handle, then the changes made will be transacted for the information classes FileBasicInfo, FileRenameInfo, FileAllocationInfo, FileEndOfFileInfo, and FileDispositionInfo. If FileDispositionInfo is specified, only the delete operation is transacted if a DeleteFile operation was requested. In this case, if the transaction is not committed before the handle is closed, the deletion will not occur. For more information about TxF, see Transactional NTFS (TxF) .
Examples
The following C++ example shows how to create a file and mark it for deletion when the handle is closed.
//...
HANDLE hFile = CreateFile (TEXT("tempfile"),
GENERIC_READ | GENERIC_WRITE | DELETE,
0 /* exclusive access */,
NULL, CREATE_ALWAYS,
0, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
FILE_DISPOSITION_INFO fdi;
fdi.DeleteFile = TRUE; // marking for deletion
BOOL fResult = SetFileInformationByHandle(
hFile,
FileDispositionInfo,
&fdi,
sizeof(FILE_DISPOSITION_INFO)
);

if (fResult)
{
// File will be deleted upon CloseHandle.
_tprintf(
TEXT("SetFileInformationByHandle marked tempfile for deletion\\n"));

// ...
// Now use the file for whatever temp data storage you need,
// it will automatically be deleted upon CloseHandle or
// application termination.
// ...
}
else
{
_tprintf(
TEXT("error %lu: SetFileInformationByHandle could not mark tempfile for deletion\\n"),
GetLastError());
}

CloseHandle(hFile);

// At this point, the file is closed and deleted by the system.
}
else
{
_tprintf(
TEXT("error %lu: could not create tempfile\\n"),
GetLastError());
}
//...
Requirements
Minimum supported clientWindows Vista
Minimum supported serverWindows Server 2008
RedistributableWindows SDK on Windows Server 2003 and Windows XP.
HeaderWinBase.h (include Windows.h), FileExtd.h on Windows Server 2003 and Windows XP
LibraryKernel32.lib, FileExtd.lib on Windows Server 2003 and Windows XP
DLLKernel32.dll
See Also
CreateFile
File Management Functions
File Security and Access Rights
Generic Access Rights
GetFileInformationByHandle
GetFileInformationByHandleEx
Send comments about this topic to Microsoft
Build date: 9/3/2009
==原始网址==http://msdn.microsoft.com/en-us/library/aa365539(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 13:21:39