Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2007

Tip: Looking for answers? Try searching our database.

Shadow Copy Wrapper?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
CMM - 14 Nov 2007 06:20 GMT
I've been scouring the net for the last few days looking for a way to copy a
locked file (create a shadow volume, expose it... that's it) from within my
program. I'm aware of the kludgy vshadow.exe commandline tool, but what I
really need is to be able to do it in managed code or via API's. I'm also
aware of the VSS SDK so I don't need a pointer to them.... just wondering if
anyone has had experience with this.
Michael Nemtsev [MVP] - 14 Nov 2007 12:36 GMT
Hello CMM,

if u aware about VSS SDK, u should noted that there is a sample of using it

did u check how that sample meets your  needs?

---
WBR,
Michael  Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour 

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

C> I've been scouring the net for the last few days looking for a way to
C> copy a locked file (create a shadow volume, expose it... that's it)
C> from within my program. I'm aware of the kludgy vshadow.exe
C> commandline tool, but what I really need is to be able to do it in
C> managed code or via API's. I'm also aware of the VSS SDK so I don't
C> need a pointer to them.... just wondering if anyone has had
C> experience with this.
C>
CMM - 14 Nov 2007 15:00 GMT
I was under the impression that the samples are C++ and not exactly portable
to the managed world. It's a shame too... because VShadow.exe... with a
little effort on the VSS team could probably be retooled into a useful
class.

> Hello CMM,
>
[quoted text clipped - 17 lines]
> C> experience with this.
> C>
Willy Denoyette [MVP] - 14 Nov 2007 15:35 GMT
The VSS team is not owning the SDK and it's samples, nor do they care about
managed code, the API is exposed through COM and C++ interfaces just like
the VSS Service. Writing a managed wrapper in C++/CLI isn't that hard
anyway. Note that as I said in another reply, you don't need VSS for this at
all.

Willy.

>I was under the impression that the samples are C++ and not exactly
>portable to the managed world. It's a shame too... because VShadow.exe...
[quoted text clipped - 22 lines]
>> C> experience with this.
>> C>
CMM - 14 Nov 2007 15:58 GMT
I don't need VSS at all? So BackupRead will alert the file's owner to flush
the file like VSS does? What if the actual copying is being done by code
other than mine? Ideally, I want to create the snapshot, pass the exposed
volume to the component to handle the rest, etc. Anyway, I was looking for a
simple solution. Looks like calling vshadow.exe and scripting it will end up
being the way to go. Shame.

> The VSS team is not owning the SDK and it's samples, nor do they care
> about managed code, the API is exposed through COM and C++ interfaces just
[quoted text clipped - 30 lines]
>>> C> experience with this.
>>> C>
Willy Denoyette [MVP] - 14 Nov 2007 21:00 GMT
>I don't need VSS at all? So BackupRead will alert the file's owner to flush
>the file like VSS does? What if the actual copying is being done by code
[quoted text clipped - 38 lines]
>>>> C> experience with this.
>>>> C>
Willy Denoyette [MVP] - 14 Nov 2007 21:13 GMT
VSS can't alert the owning program unless this one implements the VSWriter
interfaces. That means that the application needs to be modified for this.
When the application does not implement VSWriter, the File System will
simply be "alerted" to flush the FS buffers, but this is no guaranteed to be
free of incomplete I/Writer operations and data corruption, the shadow image
is said to be in a "Crash-Consistent state". If you need application
recovery state, you have to implement a writer in the application owning the
file(s).

Willy.

>I don't need VSS at all? So BackupRead will alert the file's owner to flush
>the file like VSS does? What if the actual copying is being done by code
[quoted text clipped - 38 lines]
>>>> C> experience with this.
>>>> C>
CMM - 14 Nov 2007 21:27 GMT
Yes, I'm aware of that. The question remains: there is no way, no working
examples, and no experience with using C# or VB.NET to create and expose a
shadow snapshot of a volume, right?

> VSS can't alert the owning program unless this one implements the VSWriter
> interfaces. That means that the application needs to be modified for this.
[quoted text clipped - 50 lines]
>>>>> C> experience with this.
>>>>> C>
Willy Denoyette [MVP] - 14 Nov 2007 22:10 GMT
That's right because like I have said, the VSS interfaces are not directly
usable from "pure" managed code, you have to write a wrapper in C++/CLI
(mixed managed unmanaged code) for this.

Willy.

> Yes, I'm aware of that. The question remains: there is no way, no working
> examples, and no experience with using C# or VB.NET to create and expose a
> shadow snapshot of a volume, right?

>> VSS can't alert the owning program unless this one implements the
>> VSWriter interfaces. That means that the application needs to be modified
[quoted text clipped - 52 lines]
>>>>>> C> experience with this.
>>>>>> C>
CMM - 15 Nov 2007 00:41 GMT
Thank you. That was my question and the title of my post. I think even a
(simple) COM object (callable from .NET) that duplicates vshadow.exe would
have been useful. Looks like I have to rethink our strategy.

> That's right because like I have said, the VSS interfaces are not directly
> usable from "pure" managed code, you have to write a wrapper in C++/CLI
[quoted text clipped - 63 lines]
>>>>>>> C> experience with this.
>>>>>>> C>
Willy Denoyette [MVP] - 14 Nov 2007 13:54 GMT
> I've been scouring the net for the last few days looking for a way to copy
> a locked file (create a shadow volume, expose it... that's it) from within
> my program. I'm aware of the kludgy vshadow.exe commandline tool, but what
> I really need is to be able to do it in managed code or via API's. I'm
> also aware of the VSS SDK so I don't need a pointer to them.... just
> wondering if anyone has had experience with this.

The VSS API's are a set of COM and C++ interfaces, none of them are directly
accessible from C#, so you'll have to write a wrapper in C++/CLI to be able
to access them from pure managed code.
Note however that using VSS only because you need to copy a locked file is
overkill, you can achieve the same functionality by using PInvoke to call
some Win32 API's.

First you need to open the file using Win32 "CreateFile" API with:
    dwDesiredACcess = 0
    dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE
    and dwFlagsAndAttributes = FILE_FLAG_BACKUP_SEMANTICS set.
The file handle returned can be used to call the "Kernel32" Backup API's
like "BackupRead", "BackupSeek" etc....
Note that this all requires the right privileges (SeBackupPrivilege) for the
caller!

Willy.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.