Solved

How to create drive image in c#

Posted on 2012-04-10
1
551 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 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