Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to create drive image in c#

Posted on 2012-04-10
1
Medium Priority
?
586 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

916 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