C++
--
Questions
--
Followers
Top Experts
I want to use VSS to create a snapshot for a folder, file, volume etc.
I have downloaded Windows 7 SDK which also comes with some samples.
But these samples i cannot understand.
Is there anyone who can help me with a sample?
Im using MinGW with netbeans and i also have Visual Studio 2010.
Thanks.
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
I have tried to follow the example on codeproject but VS comes with an error:






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
will get back to you,
thanks, jkr.
Volume Shadow Copy Service error: A critical component required by the Volume Shadow Copy service is not registered. This might happened if an error occurred during Windows setup or during installation of a Shadow Copy provider. The error returned from CoCreateInstance on class with CLSID {e579ab5f-1cc4-44b4-bed9-d
Operation:
Instantiating VSS server
So i found that is was building a 32 bit app on a x64 bit app which is not a good idea.
So for everyone change your project type in VS to x64 in the configuration manager.
I will get back to your later, Jkr regarding the post you posted.

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
I took my very long time to finally find a way to backup a file. Microsoft Documentation on this(Volume shadow copy for Developers) is so lame that i don't want to use Windows anymore after i finished this application.
However i got it working and for all othe peops, here is the source. The only license is that you agree with me that microsoft is stupid sometimes, then you can distribute it for free :)
// nytest.cpp : Defines the entry point for the console application.
//
#include <comdef.h>
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
int retcode = 0;
int i = 0;
HRESULT hr;
IVssEnumObject *pIEnumSnapshots;
IVssBackupComponents *ab;
VSS_OBJECT_PROP Prop;
VSS_SNAPSHOT_PROP& Snap = Prop.Obj.Snap;
WCHAR existingFilePath[MAX_PATH] = TEXT("C:\\PageFile.sys");
WCHAR newFileLocation[MAX_PATH] = TEXT("C:\\PageFileTEST.sys");
TCHAR existingFileLocation[MAX_PATH];
TCHAR sourceFile[_MAX_PATH] = TEXT("C:\\PageFile.sys");
LPTSTR DestinationFile = TEXT("D:\\PageFileTEST.sys");
if(CoInitialize(NULL) != S_OK)
{
return 2;
} // initialize security
if(FAILED(CoInitializeSecurity(NULL,-1,NULL,NULL,RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
RPC_C_IMP_LEVEL_IDENTIFY,NULL,EOAC_NONE,NULL))) {
return(0);
}
hr = CreateVssBackupComponents(&ab);
if(hr != S_OK)
{
_com_error error(hr);
LPCTSTR errorText = error.ErrorMessage();
return 2;
}
hr = ab->InitializeForBackup();
if(hr != S_OK)
{
_com_error error(hr);
LPCTSTR errorText = error.ErrorMessage();
printf("erorr..");
return 4;
}
IVssAsync *pAsync = NULL;
hr = ab->GatherWriterMetadata(&pAsync);
if(hr != S_OK)
{
_com_error error(hr);
LPCTSTR errorText = error.ErrorMessage();
return 5;
}
hr = pAsync->Wait();
if(hr != S_OK)
{return 1;}
pAsync->Release();
VSS_ID snapshotID;
hr = ab->StartSnapshotSet(&snapshotID);
if(hr != S_OK)
{
_com_error error(hr);
LPCTSTR errorText = error.ErrorMessage();
return 6;
}
VSS_ID SnapShotId;
WCHAR volumeName[4] = TEXT("C:\\");
hr = ab->AddToSnapshotSet(volumeName,GUID_NULL,&SnapShotId);
if(hr != S_OK)
{
_com_error error(hr);
LPCTSTR errorText = error.ErrorMessage();
return 7;
}
hr = ab->SetBackupState(false,false,VSS_BT_FULL,true);
if(hr != S_OK)
{
_com_error error(hr);
LPCTSTR errorText = error.ErrorMessage();
return 1;
}
IVssAsync *pPrepare = NULL;
hr = ab->PrepareForBackup(&pPrepare);
if(hr != S_OK)
{
_com_error error(hr);
LPCTSTR errorText = error.ErrorMessage();
return 8;
}
hr = pPrepare->Wait();
if(hr != S_OK)
{
_com_error error(hr);
LPCTSTR errorText = error.ErrorMessage();
return 9;
}
IVssAsync *pDoShadowCpy = NULL;
hr = ab->DoSnapshotSet(&pDoShadowCpy);
if(hr != S_OK)
{
_com_error error(hr);
LPCTSTR errorText = error.ErrorMessage();
return 10;
}
hr = pDoShadowCpy->Wait();
if(hr == S_OK)
{
VSS_SNAPSHOT_PROP snapshotprop = {0};
hr = ab->GetSnapshotProperties(SnapShotId,&snapshotprop);
_com_error error(hr);
LPCTSTR errorText = error.ErrorMessage();
if(hr == S_OK)
{
int sourcelength = wcslen(snapshotprop.m_pwszSnapshotDeviceObject) + _tcslen(sourceFile);
WCHAR test[260];
wsprintf(test,L"%s%s",snapshotprop.m_pwszSnapshotDeviceObject,L"C:\\logFile.log");
CopyFile(test,L"C:\\test.txt",false);
//exit(1);
LPTSTR sourcesnapshotfile = new TCHAR[sourcelength];
_tcscpy_s(sourcesnapshotfile,sourcelength,snapshotprop.m_pwszSnapshotDeviceObject);
_tcscat_s(sourcesnapshotfile,sourcelength,&sourceFile[2]);
if(!::CopyFile(sourcesnapshotfile,DestinationFile,FALSE))
{
DWORD lastError = GetLastError();
}
else
{
printf("File copied..");
}
delete[] sourcesnapshotfile;
VssFreeSnapshotProperties(&snapshotprop);
pDoShadowCpy->Release();
/*pPrepare->Release();*/
LONG deletedsnapshotid = 0;
VSS_ID nonDeletedSnapshotID;
hr = ab->DeleteSnapshots(SnapShotId,VSS_OBJECT_SNAPSHOT,true,&deletedsnapshotid,&nonDeletedSnapshotID);
if(hr != S_OK)
{
return 11;
}
}
}
return 0;
}
I know the code can be trimmed and i some scenarios i have hardocoded some argumetns where noramlly you will put in variables Β such as Volume(C:\,D:\).
While using this please make sure that the shadows are deleted Β use vssadmin list shadows
Jkr, i believe you should have the points for the links you provided. I did not fix my problems, but it pointed me in some direction.
I really appreciate your help. Have a nice day.
C++
--
Questions
--
Followers
Top Experts
C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.