title: Volume Shadow Copy in C++
body: <p>I'm developing an application which will need to copy files that are locked. I intend on using the Volume Shadow Copy service in Windows XP+ but I'm running into a problem with the implementation. </p>
  
  <p>I am currently getting E_ACCESSDENIED when attempting calling <code>CreateVssBackupComponents()</code> which I believe is down to not having backup privileges so I am adjusting the process privilege token to include SE_BACKUP_NAME which succeeds but I still get the error.</p>
  
  <p>My code so far (error checking removed for brevity):</p>
  
  <pre><code>CoInitialize(NULL);
  
  OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &amp;hToken);
  LookupPrivilegeValue(NULL, SE_BACKUP_NAME, &amp;luid);
  NewState.PrivilegeCount = 1;
  NewState.Privileges[0].Luid = luid;
  NewState.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  AdjustTokenPrivileges(hToken, FALSE, &amp;NewState, 0, NULL, NULL);
  
  IVssBackupComponents *pBackup = NULL;
  HRESULT result = CreateVssBackupComponents(&amp;pBackup);
  
  // result == E_ACCESSDENIED at this point
  
  pBackup-&gt;InitializeForBackup();
  &lt;snip&gt;
  </code></pre>
  
  <p>Can anyone help me out or point me in the right direction? Hours of googling have turned up very little on Volume Shadow Copy service.</p>
  
  <p>Thanks,
  J</p>