Solved

How to create drive image in c#

Posted on 2012-04-10
1
541 Views
Last Modified: 2012-04-27
How can  I create a drive image of my C drive in Visual c# 2010?  I would later want to restore it in c#.
This is for a Server 2003 - not 2008
0
Comment
Question by:pdering
1 Comment
 
LVL 4

Accepted Solution

by:
Sathish DV earned 500 total points
ID: 37831172
For taking image of physical drive, u have to use PInvoke methods to achieve with C#.
U have to use DLLImport attribute and invoke the Win32 API as shown below. You have to import the right Win32 api and proceed. As far as I know Kernel32.dll has the functions to take drive image as this dll is responsible for drive imaging through windows default drive image feature.
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "CreateFileW", SetLastError = true)]

Example code shown below.

[DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "CreateFileW", SetLastError = true)]
public static extern IntPtr CreateFile(string name, int access, int share, byte[] attributes, int create, int flags, IntPtr template);

[DllImport("kernel32.dll", SetLastError = true)]
public static extern int CloseFileHandle(IntPtr handle);

[DllImport("kernel32.dll", SetLastError = true)]
public static extern int DeviceIOControl(IntPtr handle, DiskIoctl ioctl, byte[] inBuffer, int inBufferSize, byte[] outBuffer, int outBufferSize, ref int bytesReturned, IntPtr overlapped);


The EntryPoint property in DLLImport attribute is the method or property in the kernel32.dll. So by invoking the method by passing required params then you could able to take the image drive. Better get the entire details of Kernel32 API and try to find the internal working of the same and try to get some idea on PInvoke feature in .NET and then proceed. Hope this helps you for right start.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

830 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