Jump to content
Xtreme .Net Talk

Recommended Posts

  • *Gurus*
Posted
Imports System.Runtime.InteropServices
Imports System.Text

Private Declare Ansi Function GetVolumeInformation Lib "Kernel32" Alias "GetVolumeInformationA" ( _
   ByVal lpRootPathName As String, _
   ByVal lpVolumeNameBuffer As StringBuilder, _
   ByVal nVolumeNameSize As Int32, _
   [b]ByRef[/b] lpVolumeSerialNumber As Int32, _
   [b]ByRef[/b] lpMaximumComponentLength As Int32, _
   [b]ByRef[/b] lpFileSystemFlags As Int32, _
   ByVal lpFileSystemNameBuffer As StringBuilder, _
   ByVal nFileSystemNameSize As Int32) As Boolean

Dim r As Boolean
Dim iSerial As Int32
Dim sbVolumeName As New StringBuilder(256)
Dim sbFileSystemName As New StringBuilder(256)

r = GetVolumeInformation("D:\", sbVolumeName, sbVolumeName.Capacity, _
   iSerial, 0, 0, sbFileSystemName, sbFileSystemName.Capacity)

MessageBox.Show(r.ToString() & " " & iSerial.ToString, Application.ProductName)

  • Leaders
Posted

I'm just reading about WMI in a book I got. Here's a chunk of code I wrote just playing around with the info in the book. It's essentially non-API method. The only frustrating thing is that I don't know what all you can get information about. The only reason I knew the format of "win32_logicaldisk.deviceid" was that I saw it in the book. There's no telling what other things you can grab as I've not found a list of them anywhere.

Public Sub ShowDriveInfo()
      Dim eDrive As New Management.ManagementObject("win32_logicaldisk.deviceid=""c:""")
       Dim sbProperties As New StringBuilder()

       eDrive.Get()

       Dim en As IEnumerator
       en = eDrive.Properties.GetEnumerator()
       While en.MoveNext
           sbProperties.Append(en.Current.Name)
           sbProperties.Append(" = ")
           sbProperties.Append(en.Current.Value)
           sbProperties.Append(vbCrLf)
       End While
       MessageBox.Show(sbProperties.ToString())
End Sub

--tim
Posted

Thanks for your reply. This is the code that I used:

 

Private Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" _

(ByVal lpRootPathName As String, _

ByVal lpVolumeNameBuffer As String, _

ByVal nVolumeNameSize As Int32, _

ByRef lpVolumeSerialNumber As System.UInt32, _

ByRef lpMaximumComponentLength As Int32, _

ByRef lpFileSystemFlags As Int32, _

ByVal lpFileSystemNameBuffer As String, _

ByVal nFileSystemNameSize As Int32) As Int32

 

Dim drvserial As System.UInt32

Dim mydrvlabel As String = Space$(200)

Dim myfilesys As String = Space$(200)

Dim i As Int32

Dim j As Int32

Dim x As Int32

Dim number As Int32

x = GetVolumeInformation("C:\", mydrvlabel, 200, drvserial, i, j, myfilesys, 200)

MsgBox(drvserial.ToString & " - " & mydrvlabel)

MsgBox(myfilesys)

 

About WMI I found this http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_logicaldisk.asp

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...