Solved

How to create drive image in c#

Posted on 2012-04-10
1
530 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now