IVssBackupComponents::SetContext method (vsbackup.h)

The SetContext method sets the context for subsequent shadow copy-related operations.


HRESULT SetContext(
  [in] LONG lContext


[in] lContext

The context to be set. The context must be one of the supported values of _VSS_SNAPSHOT_CONTEXT or a supported bit mask (or bitwise OR) of _VSS_VOLUME_SNAPSHOT_ATTRIBUTES with a valid _VSS_SNAPSHOT_CONTEXT.

Return value

The default return value of this method is S_OK. The following are the valid return codes for this method.

Value Meaning
Successfully set the context.
One of the parameter values is not valid.
The backup components object is not initialized, this method has been called during a restore operation, or this method has not been called within the correct sequence.
Unexpected error. The error code is logged in the error log file. For more information, see Event and Error Handling Under VSS.

Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP:  This value is not supported until Windows Server 2008 R2 and Windows 7. E_UNEXPECTED is used instead.


The default context for VSS shadow copies is VSS_CTX_BACKUP.

Windows XP:  The only supported context is the default context, VSS_CTX_BACKUP. Therefore, calling SetContext under Windows XP returns E_NOTIMPL.

SetContext can be called only once, and it must be called prior to calling most VSS functions.

For details on how the context set by IVssBackupComponents::SetContext affects how a shadow copy is created and managed, see Implementation Details for Creating Shadow Copies.

For a complete discussion of the permitted shadow copy contexts, see _VSS_SNAPSHOT_CONTEXT and _VSS_VOLUME_SNAPSHOT_ATTRIBUTES.


Minimum supported client Windows XP [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Target Platform Windows
Header vsbackup.h (include VsBackup.h, Vss.h, VsWriter.h)
Library VssApi.lib

See also