СообЧа > База Знаний > Программирование > Visual Basic

Вопрос

Как в VBA получить серийный номер диска?

Ответ

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

Sub useapi()
   Cells(1, 1) = GetSerialID
End Sub

Public Function GetSerialID() As String
On Error GoTo ErrHandler
Dim Serial As Long
Dim VName As String
Dim FSName As String

   VName = String$(255, Chr$(0))
   FSName = String$(255, Chr$(0))

   'получаем информацию о диске
   GetVolumeInformation "C:\", VName, 255, Serial, 0, 0, FSName, 255

   GetSerialID = Serial

Exit Function
ErrHandler:
&nbMsgBox Err.Number & " — " & Err.Description
End Function


vitarada

dim fso, drv, sn
set fso=createobject("Scripting.FileSystemObject")
set drv = fso.getDrive("c:")
sn=drv.SerialNumber

Shemyakin, Dmitry



Copyright © 2000-2004 Сообщество Чайников
Контактная информация