C# - Copy hard drive Sector by Sector RRS feed

  • Question

  • Is there any way with C# to do a physical copy of a hard drive, i.e. copy a hard drive sector by sector??

    thank you for your help

    Saturday, June 9, 2018 12:02 AM

All replies

  • Are you asking how to write a program to do that or are you asking what existing program will do that?

    Sam Hobbs

    Saturday, June 9, 2018 1:34 AM
  • Not directly in C#. To do a sector by sector copy you'd have to slip down to the drive level itself and .NET doesn't provide anything beyond the basic Win32 functionality. Windows itself supports it (ignoring security) but to use that functionality you'd have to use P/Invoke. An article is given here.

    But as you can see in the article you'll be working with a lot of stuff that would have to be marshalled to managed code. Doable but I'd really question why you would bother. In this particular case it would probably be better to just use a native library and C++ directly.

    If you need to access it from C# then perhaps expose a couple of simple functions that you can P/Invoke to. Alternatively you might be able to use an existing library. Here's one I found by googling. Maybe it meets your needs and maybe it doesn't. I've never used it myself.

    Michael Taylor

    • Proposed as answer by Dolen Zhang Monday, June 11, 2018 7:21 AM
    Saturday, June 9, 2018 2:18 AM