Programming using the Windows Volume Shadow Copy Service (VSS) on the .NET platform in C# (or VB) seems to be somewhat problematic to say the least. I have read numerous posts online about this issue, without ever finding a robust solution that would allow me to access the VSS API from within my .NET application. (See also my previous post).
A long discussion about these issues can for example be found in the post Announcing Hobocopy, and several others are available online, so I won’t go into that here.
The solution however, seems to be to write a custom wrapper in managed C++, that provides a managed interface that can be used from .NET and C#. There are quite a few interfaces and enumerations and the likes, so it is not a project one particularly would like to do, but for some reason I took it upon myself to do this.
So here is AlphaVSS 0.5 alpha. It is distributed under the MIT license and can be freely used by anyone according to the terms in that license.
Currently it is completely undocumented, but that should not pose to much of a problem, since MSDN has extensive documentation on the VSS API. AlphaVSS just wraps the interfaces of the VSS API in managed classes. The few items below should be enough to use the library with only the documentation found on MSDN.
- The Interfaces of the VSS API is exposed as classes in AlphaVSS. So IVssBackupComponents becomes VssBackupComponents, IVssSnapshotProp becomes VssSnapshotProp and so on.
- Enumerations are CamelCased, so eg. _VSS_SNAPSHOT_CONTEXT becomes VssSnapshotContext. In addition, the values defined in the enumerations are also CamelCased and any prefix removed. So VSS_CTX_FILE_SHARE_BACKUP becomes FileShareBackup.
- Errors are handled by exceptions and not return codes.
- Some methods return a value instead of using an out parameter. This should be clear from the method signature.
- The IVssBackupComponents::QuerySnapshot interface is changed somewhat. It returns an IEnumerable<IVssObjectProp>. IVssObjectProp is a common interface to the VssSnapshotProp and VssProviderProp classes, providing the Type accessor. This is instead of the cumbersom enumeration interface available in the original COM interfaces.
- … any additional things you may find.
The use of the same signatures in most methods (or pretty similar ones anyway) is not the best way to design things in C# or .NET in general, and I will probably improve the interface and make it conform more to common C# design practices to further simplify its use in .NET.
Please remember that this library currently is not very well tested, it is still in early alpha state. But all the tests I’ve performed seem to work just fine.
The solution and project files supplied are for Visual Studio 2008.
Please leave a comment and tell me if you find this useful or if you discover any bugs.
The latest version of the library can be downloaded from the Downloads page.