[英]Volume Shadow Copy in C++
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.
我打算在Windows XP +中使用卷影复制服务,但我遇到了实现问题。
I am currently getting E_ACCESSDENIED when attempting calling CreateVssBackupComponents()
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. 我在尝试调用
CreateVssBackupComponents()
时正在获取E_ACCESSDENIED,我认为这是因为没有备份权限所以我正在调整进程权限令牌以包含成功的SE_BACKUP_NAME,但我仍然得到错误。
My code so far (error checking removed for brevity): 到目前为止我的代码(为简洁起见,删除了错误检查):
CoInitialize(NULL);
OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken);
LookupPrivilegeValue(NULL, SE_BACKUP_NAME, &luid);
NewState.PrivilegeCount = 1;
NewState.Privileges[0].Luid = luid;
NewState.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &NewState, 0, NULL, NULL);
IVssBackupComponents *pBackup = NULL;
HRESULT result = CreateVssBackupComponents(&pBackup);
// result == E_ACCESSDENIED at this point
pBackup->InitializeForBackup();
<snip>
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.
卷影复制服务的谷歌搜索时间很少。
Thanks, J 谢谢,J
You're missing the required 4th arg on AdjustTokenPrivileges() which is DWORD BufferLength. 你错过了AdjustTokenPrivileges()所需的第4个arg,它是DWORD BufferLength。 See http://msdn.microsoft.com/en-us/library/aa375202(VS.85).aspx
见http://msdn.microsoft.com/en-us/library/aa375202(VS.85).aspx
Plus you need to always check your OS API results ;) 另外,您需要始终检查您的OS API结果;)
here is some example code: 这是一些示例代码:
TOKEN_PRIVILEGES tp;
TOKEN_PRIVILEGES oldtp;
DWORD dwSize = sizeof (TOKEN_PRIVILEGES);
ZeroMemory (&tp, sizeof (tp));
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if (AdjustTokenPrivileges(hToken, FALSE, &tp,
sizeof(TOKEN_PRIVILEGES), &oldtp, &dwSize))
{
DWORD lastError = GetLastError();
switch (lastError)
{
case ERROR_SUCCESS:
// success
break;
case ERROR_NOT_ALL_ASSIGNED:
// fail
break;
default:
// unexpected value!!
}
}
else
{
// failed! check GetLastError()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.