Copy a file using Volume Shadow Service

Posted on 2009-02-16
Last Modified: 2012-05-06
I am using Visual Studio 2008 working with VB.NET.

What I want to do is create a small app for myself that can make a copy of some of my files which are often locked by the system.

I'm told this can be done in a way, you can get a copy of whats written on the disk by accessing a snapshot of the file using the volume shadow service. I understand this may not be the entire file if data hasn't yet been written.

Can anyone provide me with a function which can access the VSS API for XP or Vista where I can pass it the path/name of the source file and the path/name of the destination file and have it make the copy?

Question by:Andy1
    LVL 18

    Expert Comment

    Have you looked at the Volume Shadow Service SDK?

    Also, there is a CodeProject page giving a use like yours:
    LVL 1

    Author Comment

    I still haven't gotten far with this... i had already downloaded the sdk.
    LVL 1

    Accepted Solution

    I had already downloaded the SDK you link to.

    The CodeProject page just had lots of errors... not sure if its because im using Visual Studio 2008 but I wasn't able to make it work. - This may also be because im using Vista.. not sure if that code is XP only.

    I'd still love a way to implement this proramitically.

    What I've found in my trolling of MSDN and the internet I found a reference to the latest Windows SDK which had some more information about the Volume shadow copy service.

    If i've understood it correctly, theres some incompatibilities between versions - so a program has to be compiled for each OS (XP, 2003 or Vista(and above)) version you want to run on.

    In the SDK as linked above, there is 2 compiled programs: 'vshadow.exe' for XP or 2003 server. In the Windows SDK I found a compled version of vshadow.exe for Vista and above.

    So while I would still love some code that can do it all programitically, I've had to go with the following solution:

    Having all 3 versions of vshadow.exe
    Detect the OS version
    Interact with the OS's version of vshadow.exe to create the copy of the file.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now