首页 /编程语言和算法/VB6/ASP
 VB6 获得C盘名字和修改名字,子程序 GetSerialNumber(sDrive As String) SetVolumeName(sDrive As String, n As String)
昨天 15:39

新建From1(窗体),新建Command1-2(按钮CommandButton),代码:

Private Declare Function GetVolumeInformation& Lib "kernel32" Alias "GetVolumeInformationA" _
   (ByVal lpRootPathName As String, ByVal pVolumeNameBuffer As String, _
    ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, _
    lpMaximumComponentLength As Long, lpFileSystemFlags As Long, _
    ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long)

Private Declare Function SetVolumeLabelA Lib "kernel32" _
   (ByVal lpRootPathName As String, _
   ByVal lpVolumeName As String) As Long
   
Private Sub Command1_Click()
    '得到C:盘名字
    MsgBox GetVolumeName("C")
End Sub

Private Sub Command2_Click()
    '修改C:盘名字
    Call SetVolumeName("C", "my-c-new")
End Sub

Private Function GetVolumeName(sDrive As String) As String
   Dim ser As Long
   Dim s As String * MAX_FILENAME_LEN
   Dim s2 As String * MAX_FILENAME_LEN
   Dim i As Long
   Dim j As Long
   
   Call GetVolumeInformation(sDrive + ":\" & Chr$(0), s, MAX_FILENAME_LEN, ser, i, j, s2, MAX_FILENAME_LEN)
   GetVolumeName = Left$(s, InStr(s, Chr$(0)) - 1)
End Function

Private Function SetVolumeName(sDrive As String, n As String) As Boolean
   Dim i As Long
   
   i = SetVolumeLabelA(sDrive + ":\" & Chr$(0), n & Chr$(0))
   
   SetVolumeName = IIf(i = 0, False, True)
End Function


 
全部回复(0)
首页 | 电脑版 |