views:

173

answers:

2

I am currently using Diskpart to accomplish these functions, but i would like to be able to use P-Invoke and not have to shell out to an external process in my C# app.

The example Diskpart scripts are:

//Online a disk
Select disk 7
disk online

// Reset GPT Identifier
select disk 7
UNIQUEID DISK ID=baf784e7-6bbd-4cfb-aaac-e86c96e166ee

I tried searching pinvoke.net but could only find functions that dealt with volumes, not disks. Any idea on how to accomplish these diskpart commands using Pinvoke?

A: 

I'm not sure exactly what Dispart does but I'd suggest looking at WMI which might have this kind of functionality. It's usually a good place to look when you need to do something less common in Windows.

There's the Storage WMI Classes which might have something useful:
http://msdn.microsoft.com/en-us/library/ff567016%28VS.85%29.aspx

Edit: removed the suggestions about Volumes since I had missed that you're not interested in that.

ho1
I did find win32_diskdrive but it doesn't have any useful methods for what I am trying to accomplish.
Andy Schneider
A: 

How about the DeviceIOControl API?

If not, I would look into using WMI. In particular, take a look at the WMI WIN32_DiskDrive or WIN32_LogicalDisk classes.

Garett
It looks like CreateFile and DeviceOControl may be where I need to start. Any examples would be great. I'm no Win32 programmer :)
Andy Schneider
I can write something up, but it's going to take some time. You can examples of using the API at http://www.pinvoke.net/default.aspx/kernel32.deviceiocontrol. This article may also be of use: http://blogs.msdn.com/b/jeffrey_wall/archive/2004/09/13/229137.aspx
Garett