问题
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?
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/2905926/win32-api-p-invoke-to-bring-a-disk-online-offline-and-set-unique-id