WUGNET, the Windows User Group Network
Your Complete Resource Center for "The Best" in Shareware, Computing Tips and Support, Windows Industry News... and much more!
Home Forums Shareware Windows Tips Hot Offers FREE Newsletters Arcade Contact Us About Partners
Search WUGNET: RSS Feeds RSS Feeds Advertise with WUGNET    |    Shareware eBooks
HomeHome FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

FILE_FLAG_BACKUP_SEMANTICS

 
   Home -> Windows Other -> File System RSS
Next:  Politics  
Author Message
Nick Tucker

External


Since: Nov 21, 2008
Posts: 1



(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.

The test rig code I'm using is as follows:

HRESULT ModifyPrivilege( IN LPCTSTR szPrivilege,
IN BOOL fEnable)
{
HRESULT hr = S_OK;
TOKEN_PRIVILEGES NewState;
LUID luid;
HANDLE hToken = NULL;

// 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;
}

// Close the handle.
CloseHandle(hToken);

return hr;
}

int main(int argc, const char *argv[])
{
HANDLE h;
HRESULT hr;

hr = ModifyPrivilege(SE_BACKUP_NAME, TRUE);

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.

Thanks in advance for any input

Cheers
Back to top
Login to vote
Display posts from previous:   
       Home -> Windows Other -> File System 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
Categories:
 Windows XP
 Windows Vista
  Windows Other
 Office
 Office Other
 Security
  • Home |
  • Shareware |
  • Windows Tips |
  • Hot Offers |
  • FREE Newsletters |
  • Arcade |
  • Forums |
  • eBooks |
  • About WUGNET |
  • Partners |
  • Contact

  • WUGNET Privacy Policy |
  • Link to WUGNET |
  • IT Support