user4266661
user4266661

Reputation:

Windows File History API: Adding Include Rule

I'm building a c#-based service to augment Windows File History.

Looking through the API I don't see a method for adding an "include" folder or library. There only seems to be a method for adding an "exclude" folder (FYI, include and exclude refers to whether or not a particular folder or library is backed up or not).

I checked the fhchg.h header file in the SDK and don't see any method for adding folders or libraries defined there, either:

EXTERN_C const IID IID_IFhConfigMgr;

#if defined(__cplusplus) && !defined(CINTERFACE)

MIDL_INTERFACE("6A5FEA5B-BF8F-4EE5-B8C3-44D8A0D7331C")
IFhConfigMgr : public IUnknown
{
public:
    virtual HRESULT STDMETHODCALLTYPE LoadConfiguration( void) = 0;

    virtual HRESULT STDMETHODCALLTYPE CreateDefaultConfiguration( 
        /* [in] */ BOOL OverwriteIfExists) = 0;

    virtual HRESULT STDMETHODCALLTYPE SaveConfiguration( void) = 0;

    virtual HRESULT STDMETHODCALLTYPE AddRemoveExcludeRule( 
        /* [in] */ BOOL Add,
        /* [in] */ FH_PROTECTED_ITEM_CATEGORY Category,
        /* [in] */ __RPC__in BSTR Item) = 0;

    virtual HRESULT STDMETHODCALLTYPE GetIncludeExcludeRules( 
        /* [in] */ BOOL Include,
        /* [in] */ FH_PROTECTED_ITEM_CATEGORY Category,
        /* [out] */ __RPC__deref_out_opt IFhScopeIterator **Iterator) = 0;

    virtual HRESULT STDMETHODCALLTYPE GetLocalPolicy( 
        /* [in] */ FH_LOCAL_POLICY_TYPE LocalPolicyType,
        /* [out] */ __RPC__out ULONGLONG *PolicyValue) = 0;

    virtual HRESULT STDMETHODCALLTYPE SetLocalPolicy( 
        /* [in] */ FH_LOCAL_POLICY_TYPE LocalPolicyType,
        /* [in] */ ULONGLONG PolicyValue) = 0;

    virtual HRESULT STDMETHODCALLTYPE GetBackupStatus( 
        /* [out] */ __RPC__out FH_BACKUP_STATUS *BackupStatus) = 0;

    virtual HRESULT STDMETHODCALLTYPE SetBackupStatus( 
        /* [in] */ FH_BACKUP_STATUS BackupStatus) = 0;

    virtual HRESULT STDMETHODCALLTYPE GetDefaultTarget( 
        /* [out] */ __RPC__deref_out_opt IFhTarget **DefaultTarget) = 0;

    virtual HRESULT STDMETHODCALLTYPE ValidateTarget( 
        /* [in] */ __RPC__in BSTR TargetUrl,
        /* [out] */ __RPC__out PFH_DEVICE_VALIDATION_RESULT ValidationResult) = 0;

    virtual HRESULT STDMETHODCALLTYPE ProvisionAndSetNewTarget( 
        /* [in] */ __RPC__in BSTR TargetUrl,
        /* [in] */ __RPC__in BSTR TargetName) = 0;

    virtual HRESULT STDMETHODCALLTYPE ChangeDefaultTargetRecommendation( 
        /* [in] */ BOOL Recommend) = 0;

    virtual HRESULT STDMETHODCALLTYPE QueryProtectionStatus( 
        /* [out] */ __RPC__out DWORD *ProtectionState,
        /* [out] */ __RPC__deref_out_opt BSTR *ProtectedUntilTime) = 0;

};


#else   /* C style interface */

typedef struct IFhConfigMgrVtbl
{
    BEGIN_INTERFACE

    HRESULT ( STDMETHODCALLTYPE *QueryInterface )( 
        __RPC__in IFhConfigMgr * This,
        /* [in] */ __RPC__in REFIID riid,
        /* [annotation][iid_is][out] */ 
        _COM_Outptr_  void **ppvObject);

    ULONG ( STDMETHODCALLTYPE *AddRef )( 
        __RPC__in IFhConfigMgr * This);

    ULONG ( STDMETHODCALLTYPE *Release )( 
        __RPC__in IFhConfigMgr * This);

    HRESULT ( STDMETHODCALLTYPE *LoadConfiguration )( 
        __RPC__in IFhConfigMgr * This);

    HRESULT ( STDMETHODCALLTYPE *CreateDefaultConfiguration )( 
        __RPC__in IFhConfigMgr * This,
        /* [in] */ BOOL OverwriteIfExists);

    HRESULT ( STDMETHODCALLTYPE *SaveConfiguration )( 
        __RPC__in IFhConfigMgr * This);

    HRESULT ( STDMETHODCALLTYPE *AddRemoveExcludeRule )( 
        __RPC__in IFhConfigMgr * This,
        /* [in] */ BOOL Add,
        /* [in] */ FH_PROTECTED_ITEM_CATEGORY Category,
        /* [in] */ __RPC__in BSTR Item);

    HRESULT ( STDMETHODCALLTYPE *GetIncludeExcludeRules )( 
        __RPC__in IFhConfigMgr * This,
        /* [in] */ BOOL Include,
        /* [in] */ FH_PROTECTED_ITEM_CATEGORY Category,
        /* [out] */ __RPC__deref_out_opt IFhScopeIterator **Iterator);

    HRESULT ( STDMETHODCALLTYPE *GetLocalPolicy )( 
        __RPC__in IFhConfigMgr * This,
        /* [in] */ FH_LOCAL_POLICY_TYPE LocalPolicyType,
        /* [out] */ __RPC__out ULONGLONG *PolicyValue);

    HRESULT ( STDMETHODCALLTYPE *SetLocalPolicy )( 
        __RPC__in IFhConfigMgr * This,
        /* [in] */ FH_LOCAL_POLICY_TYPE LocalPolicyType,
        /* [in] */ ULONGLONG PolicyValue);

    HRESULT ( STDMETHODCALLTYPE *GetBackupStatus )( 
        __RPC__in IFhConfigMgr * This,
        /* [out] */ __RPC__out FH_BACKUP_STATUS *BackupStatus);

    HRESULT ( STDMETHODCALLTYPE *SetBackupStatus )( 
        __RPC__in IFhConfigMgr * This,
        /* [in] */ FH_BACKUP_STATUS BackupStatus);

    HRESULT ( STDMETHODCALLTYPE *GetDefaultTarget )( 
        __RPC__in IFhConfigMgr * This,
        /* [out] */ __RPC__deref_out_opt IFhTarget **DefaultTarget);

    HRESULT ( STDMETHODCALLTYPE *ValidateTarget )( 
        __RPC__in IFhConfigMgr * This,
        /* [in] */ __RPC__in BSTR TargetUrl,
        /* [out] */ __RPC__out PFH_DEVICE_VALIDATION_RESULT ValidationResult);

    HRESULT ( STDMETHODCALLTYPE *ProvisionAndSetNewTarget )( 
        __RPC__in IFhConfigMgr * This,
        /* [in] */ __RPC__in BSTR TargetUrl,
        /* [in] */ __RPC__in BSTR TargetName);

    HRESULT ( STDMETHODCALLTYPE *ChangeDefaultTargetRecommendation )( 
        __RPC__in IFhConfigMgr * This,
        /* [in] */ BOOL Recommend);

    HRESULT ( STDMETHODCALLTYPE *QueryProtectionStatus )( 
        __RPC__in IFhConfigMgr * This,
        /* [out] */ __RPC__out DWORD *ProtectionState,
        /* [out] */ __RPC__deref_out_opt BSTR *ProtectedUntilTime);

    END_INTERFACE
} IFhConfigMgrVtbl;

interface IFhConfigMgr
{
    CONST_VTBL struct IFhConfigMgrVtbl *lpVtbl;
};

Yet folders/libraries can be included via the desktop settings interface to File History. So I'm obviously missing something.

Upvotes: 2

Views: 177

Answers (2)

Dustin Wyatt
Dustin Wyatt

Reputation: 4244

AFAICT, there is no such API. As a super hacky and not-recommended workaround, my script directly edits the Config1.xml and Config2.xml files in %LOCALAPPDATA%/Microsoft/Windows/FileHistory/Configuration. Not sure if it's necessary but I also stop and disable the File History service before making the edit.

(No, I do not know why there are two identical config files for this)

Upvotes: 0

Rita Han
Rita Han

Reputation: 9710

The File History protection scope is the set of files that are backed up by the File History feature. It contains inclusion rules and exclusion rules. The default protection scope includes all folders from all user libraries and the Contacts, Desktop, and Favorites folders.

Refer to "IFhConfigMgr::AddRemoveExcludeRule method".

So you don't need adding an "include" folder or library, just add an "exclude" when you don't need file history of a folder to be backed up.

Upvotes: 2

Related Questions