0

I'm trying to use VSS Express Writer to include one of my folders in the restore point when it is conducted. Although the code seem to runs without any errors I don't get the expected result and the folder isn't kept when i go back to restore point.

To verify my code functionality, I could trace my writer in vssadmin list writers.

I am doing the following flow:

  1. Register using the following code (see below).
  2. Create system restore point.
  3. Delete my folder.
  4. Restart
  5. Restore my system.

Unfortunately, I dont get my folder back..

int main()
{
    ::CoInitialize(NULL);

    createAndRegister();

}

int createAndRegister()
{
    CComPtr<IVssExpressWriter>                  spExpressWriter;
    CComPtr<IVssCreateExpressWriterMetadata>    spMetadata;

    CreateVssExpressWriter(&spExpressWriter);

    spExpressWriter->CreateMetadata(EXPRESS_WRITER_SAMPLE_GUID, L"Sample Express Writer", VSS_UT_USERDATA, 1, 0, 0, &spMetadata);

    PCWSTR  wszComponent = L"myExpressWriter";


    spMetadata->SetRestoreMethod(
        VSS_RME_RESTORE_AT_REBOOT, ////I've also tried it with different option of this enum
        NULL,
        NULL,                              
        VSS_WRE_NEVER,                     
        false),
        L"SetRestoreMethod failed");

    spMetadata->AddComponent(
        VSS_CT_FILEGROUP,
        NULL,
        wszComponent,
        wszComponent,
        NULL,
        0,
        false,
        false,
        false);   

    spMetadata->AddFilesToFileGroup(
        NULL,
        wszComponent,
        L"c:\\ProgramData\\myFolder",
        L"*.*",
        true,
        NULL,
        NULL),


    spExpressWriter->Register();
}

procmon recording was set during system restore point, and no event that contain the path to myFolder was found at the time... is it possible that the file adding is made during the registration to vsswriter, and not during the restore point creation ?

Perhaps anyone can help me find what am i missing here?

thanks

Irad K
  • 867
  • 6
  • 20
  • *"the code seem to runs without any errors"* - Have you checked? All those COM calls return an `HRESULT`, but your code simply ignores it. Or is this not the code you are using for testing? – IInspectable Aug 11 '19 at 21:34
  • Please check which function failed. Use GetLastError() to get the error message. If it is [0x80042302], you should open Services, then find Volume Shadow Copy, right click to open the property, change the startup type to automatic, and change the service state to start. – Jeffreys Aug 12 '19 at 06:42
  • @JeffreyShao-MSFT, thanks for the help, this code is actually for emphasis the flow so I skipped the error checking. in the original code however, the checking exists but no error is shown. – Irad K Aug 12 '19 at 07:17
  • @jef: COM does not report errors by means of the calling thread's last error code. Calling `GetLastError` returns meaningless results in COM programming. – IInspectable Aug 12 '19 at 15:38
  • @lln:thanks, i just see the function in Microsoft samlpe. – Jeffreys Aug 13 '19 at 02:07
  • The `AddFilesToFileGroup` method adds a file set (a specified file or files) to a specified **file group component**. – Jeffreys Aug 15 '19 at 07:09
  • @JeffreyShao-MSFT, right ... in this example I've used regular expression, but i wasn't working even if I specified a single file with non supported extension (.txt) which i want to add to the restore point. Do you see why this is not working ? – Irad K Aug 15 '19 at 07:15

0 Answers0