How can I get identity of a disk?

假如想象 提交于 2020-01-14 06:03:00

问题


I want to identify disk in c++ in my windows application. For example: I have a disk on E:\ Then I changed the disk, and replace it with another one. the name is still E:\ How can I know the disk is changed, it is not the original one?

If I have no administrator priority in win7, Can I still use some method to identy different disks?

Many thanks!


回答1:


Probably the relevant methods are:

GetLogicalDrives()

BOOL WINAPI GetVolumeInformation( __in_opt LPCTSTR lpRootPathName, __out LPTSTR lpVolumeNameBuffer, __in DWORD nVolumeNameSize, __out_opt LPDWORD lpVolumeSerialNumber, __out_opt LPDWORD lpMaximumComponentLength, __out_opt LPDWORD lpFileSystemFlags, __out LPTSTR lpFileSystemNameBuffer, __in DWORD nFileSystemNameSize )

GetDriveType(string vol)

GetVolumeInformation will give you the serial number. If this isn't enough you will probably have to resort to WMI_PhysicalMedia. I believe all of this should work without Administrator privileges.

A page listing a bunch of relevant functions is here: http://msdn.microsoft.com/en-us/library/aa365730(v=VS.85).aspx



来源:https://stackoverflow.com/questions/2636314/how-can-i-get-identity-of-a-disk

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