我也在尝试使用FILE_FLAG_BACKUP_SEMANTICS
后更改目录的时间戳。
我的代码段如下
int SetDirectoryTime(char *Path)
{
FILETIME ftCreate, ftAccess, ftWrite;
Handle = CreateFile(Path, GENERIC_WRITE, FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
if (Handle == INVALID_HANDLE_VALUE)
{
//Unable to open directory
return FALSE;
}
if (SetFileTime(Handle, &ftCreate, &ftAccess, &ftWrite) == 0)
{
//Unable to set directory time
CloseHandle(Handle);
return FALSE;
}
}
我能够获得一个有效的句柄,但SetFileTime正在返回Access denied。
我为SE_BACKUP_NAME
尝试了EnablePrivilege,SE_RESTORE_NAME
仍然拒绝访问。
答案 0 :(得分:3)
答案 1 :(得分:0)
const
cWRITE_FILE_ATTIRIBUTES = $100; // not defined in Delphi7
var
cfAttributes : dword;
cfDesiredAccess : dword;
cfShareMode : dword;
hndFile : THandle;
ftAccessed : TFileTime;
ftCreated : TFileTime;
ftModified : TFileTime;
begin
cfAttributes := cWRITE_FILE_ATTIRIBUTES OR FILE_FLAG_BACKUP_SEMANTICS;
cfDesiredAccess := GENERIC_READ OR GENERIC_WRITE;
cfShareMode := FILE_SHARE_READ OR FILE_SHARE_WRITE;
hndFile := CreateFile(pchar(_FQFN),
cfDesiredAccess,
cfShareMode,
nil,
OPEN_EXISTING,
cfAttributes,
0);
SetFileTime(hndFile, @ftCreated, @ftAccessed, @ftModified);
end;
此代码在Delph7下可以正常工作,以更改目录的时间戳。 _FQFN是带有反斜杠的路径。
为清楚起见,错误检查已删除并格式化。