Win32 API P-Invoke to bring a disk online, offline, and set unique ID

风格不统一 提交于 2019-12-10 23:40:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!