office交流网--QQ交流群号

Access培训群:792054000         Excel免费交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

Access Excel VBA通过API修改硬盘卷标(Disk Label)

2020-02-26 08:00:00
zstmtony
原创
3563

Access Excel VBA通过API修改硬盘卷标(Disk Label) 俗称硬盘标签 或硬盘别名--Change the Drive Volume Label



调用了: Windows 系统 API



Option Explicit

Private Declare Function SetVolumeLabel Lib "kernel32" Alias _
   "SetVolumeLabelA" (ByVal lpRootPathName As String, _
   ByVal lpVolumeName As String) As Long
 
Public Function gf_ChangeDiskLabel(strDriver As String, strNewDriveLabel As String) As Boolean
 
Dim lngRet As Long  
 
On Error Resume Next
lngRet = SetVolumeLabel(strDriver , strNewDriveLabel ) 'office-cn.net ChangeDiskLabel = (lngRet <> 0)
    
End Function


'使用方法

'ChangeDiskLabel("F:", "Office中国数据盘")



vb.net方法

        Dim int As Integer = 0
        For Each di As System.IO.DriveInfo In System.IO.DriveInfo.GetDrives
            Try
                di.VolumeLabel = "Test" & int.ToString
                int += 1
            Catch ex As Exception
 
            End Try
        Next

分享