bogdandaniel Posted March 28, 2003 Posted March 28, 2003 :( How can I use the api GetVolumeInformation in VB.NET to get the hard disk serial number? If I use the same code like in VB 6 the serial is always 0! Please help me Thanks Quote
*Gurus* divil Posted March 28, 2003 *Gurus* Posted March 28, 2003 Can you post the code you're trying to use? Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
*Gurus* Derek Stone Posted March 28, 2003 *Gurus* Posted March 28, 2003 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) Quote Posting Guidelines
Leaders quwiltw Posted March 29, 2003 Leaders Posted March 29, 2003 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 Quote --tim
bogdandaniel Posted March 31, 2003 Author Posted March 31, 2003 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 Quote
Recommended Posts