(Msg. 1) Posted: Fri Nov 21, 2008 2:58 pm
Post subject: FILE_FLAG_BACKUP_SEMANTICS Archived from groups: microsoft>public>win2000>file_system (more info?)
Hi everyone
I have a data backup program which I'm trying to modify to allow backing up
of files in use.
The documentation implies this can be done if I grant myself the
SE_BACKUP_NAME privilege, then use CreateFile() specifying flag
FILE_FLAG_BACKUP_SEMANTICS. Unfortunately, this is not working for me.
// Open the process token for this process.
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES |
TOKEN_QUERY,
&hToken ))
{
printf("Failed OpenProcessToken\n");
return ERROR_FUNCTION_FAILED;
}
// Get the local unique ID for the privilege.
if ( !LookupPrivilegeValue( NULL,
szPrivilege,
&luid ))
{
CloseHandle( hToken );
printf("Failed LookupPrivilegeValue\n");
return ERROR_FUNCTION_FAILED;
}
// Assign values to the TOKEN_PRIVILEGE structure.
NewState.PrivilegeCount = 1;
NewState.Privileges[0].Luid = luid;
NewState.Privileges[0].Attributes =
(fEnable ? SE_PRIVILEGE_ENABLED : 0);
// Adjust the token privilege.
if (!AdjustTokenPrivileges(hToken,
FALSE,
&NewState,
0,
NULL,
NULL))
{
printf("Failed AdjustTokenPrivileges\n");
hr = ERROR_FUNCTION_FAILED;
}
// Get the local unique ID for the privilege.
if ( !LookupPrivilegeValue(NULL,
szPrivilege,
&luid ))
{
CloseHandle( hToken );
printf("Failed LookupPrivilegeValue\n");
return ERROR_FUNCTION_FAILED;
}
if (!SUCCEEDED(hr))
printf("\nFailed to modify privilege.\n");
else
printf("\nSuccessfully modified privilege.\n");
h=CreateFile("C:\\test.xls",
READ_CONTROL,
0,
NULL,
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS,
NULL);
if (h!=NULL)
{
CloseHandle(h);
printf("\nSuccessfully opened file");
}
else
printf("\nFailed to open file");
}
Unfortunately, when this code is run, 0xffffffff is always returned by
CreateFile() if the file is open by Excel, with GetLastError() returning
error 32 'The process cannot access the file because it is in use by another
process'. I have tried this on a variety of operating systems and using
Administrative login accounts who are members of the 'Backup Operators'.
Why?
Surely, the whole point of having the FILE_FLAG_BACKUP_SEMANTICS
would be to allow this.
All times are: Eastern Time (US & Canada) (change)
Page 1 of 1
You can post new topics in this forum You can reply to topics in this forum You can edit your posts in this forum You can delete your posts in this forum You can vote in polls in this forum