|
-
Oct 19th, 2011, 09:21 AM
#1
Thread Starter
Addicted Member
Getting Drive Names
If I:
1. hit Ctrl + E,
2. then right click a drive in the "Devices with Removable Storage" and select properties.
3. click the hardware tab.
A very detailed name for each of the disk drives is listed.
Is there a way to get access to these displayed drive names?
All men have an inherent right to life, the right to self determination including freedom from forced or compulsory labour, a right to hold opinions and the freedom of expression, and the right to a fair trial and freedom from torture. Be aware that these rights are universal and inalienable (cannot be given, taken or otherwise transferred or removed) although you do risk losing the aforementioned rights should you fail to uphold them e.g Charles Taylor; United Nations sources: http://www.un.org/en/documents/udhr/, http://www.ohchr.org/EN/Professional...ages/CCPR.aspx. Also Charles I was beheaded on the 30th of January of 1649 for trying to replace parliamentary democracy with an absolute monarchy, the same should happen to Dr Phil and Stephen Fry; source: http://www.vbforums.com/showthread.p...ute-Monarchism.
The plural of sun is stars you Catholic turkeys.
-
Oct 19th, 2011, 10:37 AM
#2
-
Oct 19th, 2011, 11:28 PM
#3
Thread Starter
Addicted Member
Re: Getting Drive Names
Thanks for the example RhinoBull, although it doesn't get me access to the drive name. Here is another example which gets me the drive label, although again it does not return the drive name:
Code:
Private Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
Function Drivelabel(ByVal sDrive As String) As String
Const clMaxLen As Long = 255
Dim SDriveLabel As String * clMaxLen, sFileSystem As String * clMaxLen, lSerial As Long
sDrive = Left$(sDrive, 1) & ":\"
Call GetVolumeInformation(sDrive, SDriveLabel, clMaxLen, lSerial, 0, 0, sFileSystem, clMaxLen)
Drivelabel = "Drive label: " & Left$(SDriveLabel, InStr(1, SDriveLabel, vbNullChar) - 1)
End Function
So you see there is a difference between the drive name and the drive label, where the drive name is set by the manufacturer while the drive label is usually set by the user. I am trying to get access to the manufacturer's information regarding the drive including the model, etc.
All men have an inherent right to life, the right to self determination including freedom from forced or compulsory labour, a right to hold opinions and the freedom of expression, and the right to a fair trial and freedom from torture. Be aware that these rights are universal and inalienable (cannot be given, taken or otherwise transferred or removed) although you do risk losing the aforementioned rights should you fail to uphold them e.g Charles Taylor; United Nations sources: http://www.un.org/en/documents/udhr/, http://www.ohchr.org/EN/Professional...ages/CCPR.aspx. Also Charles I was beheaded on the 30th of January of 1649 for trying to replace parliamentary democracy with an absolute monarchy, the same should happen to Dr Phil and Stephen Fry; source: http://www.vbforums.com/showthread.p...ute-Monarchism.
The plural of sun is stars you Catholic turkeys.
-
Oct 20th, 2011, 11:50 PM
#4
Thread Starter
Addicted Member
Re: Getting Drive Names
In the absence of an API to get this information, I had to get it via the WMI.
Code:
Option Explicit
' set a reference to the scripting runtime via Project->References->Microsoft Scripting Runtime
' To a form with a command button
' Inspired by http://vbnet.mvps.org/index.html?code/wmi/win32_diskdrive.htm
Private Sub Command1_Click()
MsgBox wmiDiskDriveInfo
End Sub
Code:
Private Function wmiDiskDriveInfo() As String
Dim DiscDrives As Object
Dim DiscDrive As Object
Set DiscDrives = GetObject("winmgmts:{impersonationLevel=impersonate}"). _
InstancesOf("Win32_DiskDrive")
'for each drive return relevant data
For Each DiscDrive In DiscDrives
wmiDiskDriveInfo = wmiDiskDriveInfo & "Model: " & DiscDrive.Model & vbCrLf
wmiDiskDriveInfo = wmiDiskDriveInfo & "Media Type: " & DiscDrive.MediaType & vbCrLf
wmiDiskDriveInfo = wmiDiskDriveInfo & "Interface: " & DiscDrive.InterfaceType & vbCrLf
wmiDiskDriveInfo = wmiDiskDriveInfo & "GB: " & FormatNumber(DiscDrive.Size / 1000000000, 2) & vbCrLf & vbCrLf
Next DiscDrive
Set DiscDrives = Nothing
Set DiscDrive = Nothing
End Function
All men have an inherent right to life, the right to self determination including freedom from forced or compulsory labour, a right to hold opinions and the freedom of expression, and the right to a fair trial and freedom from torture. Be aware that these rights are universal and inalienable (cannot be given, taken or otherwise transferred or removed) although you do risk losing the aforementioned rights should you fail to uphold them e.g Charles Taylor; United Nations sources: http://www.un.org/en/documents/udhr/, http://www.ohchr.org/EN/Professional...ages/CCPR.aspx. Also Charles I was beheaded on the 30th of January of 1649 for trying to replace parliamentary democracy with an absolute monarchy, the same should happen to Dr Phil and Stephen Fry; source: http://www.vbforums.com/showthread.p...ute-Monarchism.
The plural of sun is stars you Catholic turkeys.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|