VisualBasic Snippets  

Auslesen und verändern des Volumennamens:
 

Mit dem untenstehenden Programm-Code können Sie den Namen einer Festplatte auslesen (incl. Dateisystem und Laufwerksnummer) und diesem Namen verändert wieder zurückspeichern.


Quelltext der Anwendung:


'API-Function deklarieren
Private Declare Function GetVolumeInformation Lib "kernel32.dll" 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

Private Declare Function SetVolumeLabel Lib "kernel32.dll" Alias "SetVolumeLabelA" _
    (ByVal lpRootPathName As String, ByVal lpVolumeName As String) As Long

'Konstante deklarieren
Const FS_CASE_IS_PRESERVED = &H2 Const FS_CASE_SENSITIVE = &H1 Const FS_UNICODE_STORED_ON_DISK = &H4 Const FS_PERSISTENT_ACLS = &H8 Const FS_FILE_COMPRESSION = &H10 Const FS_VOLUME_IS_COMPRESSED = &H8000 Const FILE_NAMED_STREAMS = &H40000 Const FILE_SUPPORTS_ENCRYPTION = &H20000 Const FILE_SUPPORTS_OBJECT_IDS = &H10000 Const FILE_SUPPORTS_REPARSE_POINTS = &H80 Const FILE_SUPPORTS_SPARSE_FILES = &H40 Const FILE_VOLUME_QUOTAS = &H20 '------------------------------------------------------------ Private Sub VolumeInformation() Dim tsStrVolname As String Dim tsStrFilesys As String Dim tsStrSN As String Dim tsLngSN As Long Dim tsLngDummy1 As Long Dim tsLngDummy2 As Long Dim tsLngRetval As Long 'Variablen füllen tsStrVolname = Space(256) tsStrFilesys = Space(256) 'Laufwerksinformationen auslesen tsLngRetval = GetVolumeInformation("C:\", tsStrVolname, Len(tsStrVolname), tsLngSN, tsLngDummy1, _ tsLngDummy2, tsStrFilesys, Len(tsStrFilesys)) 'String zurechtschneiden tsStrVolname = Left(tsStrVolname, InStr(tsStrVolname, vbNullChar) - 1) tsStrFilesys = Left(tsStrFilesys, InStr(tsStrFilesys, vbNullChar) - 1) 'Seriennummer formatieren tsStrSN = Trim(Hex(tsLngSN)) tsStrSN = String(8 - Len(tsStrSN), "0") & tsStrSN tsStrSN = Left(tsStrSN, 4) & "-" & Right(tsStrSN, 4) 'Parameter anzeigen txtVolumename.Text = tsStrVolname txtNumber.Caption = "Datenträgernummer: " & tsStrSN txtFileSystem.Caption = "Dateisystem: " & tsStrFilesys End Sub '------------------------------------------------------------ Private Sub btnChgVolume_Click() Dim tsLngRetval As Long 'Laufwerkbezeichnung ändern tsLngRetval = SetVolumeLabel("C:\", txtVolumename.Text) VolumeInformation End Sub '------------------------------------------------------------ Private Sub btnClose_Click() End End Sub '------------------------------------------------------------ Private Sub Form_Load() VolumeInformation End Sub

  Download VB6
Projekt-Quellcode
Download
Demo-Exe

© '2000 by T. Schindzielorz