在vb6中将\Device\HarddiskVolume1转换为C:

在vb6中将\Device\HarddiskVolume1转换为C:,vb6,Vb6,在visual basic 6中,是否有任何方法可以将\Device\HarddiskVolume1\programfile\explorer.exe转换为C:\programfile\explorer.exe 谢谢你试试这个 Option Explicit Private Declare Function QueryDosDevice Lib "kernel32" Alias "QueryDosDeviceA" (ByVal lpDeviceName As String, ByVal lpT

在visual basic 6中,是否有任何方法可以将
\Device\HarddiskVolume1\programfile\explorer.exe
转换为
C:\programfile\explorer.exe

谢谢你试试这个

Option Explicit

Private Declare Function QueryDosDevice Lib "kernel32" Alias "QueryDosDeviceA" (ByVal lpDeviceName As String, ByVal lpTargetPath As String, ByVal ucchMax As Long) As Long

Private Sub Command1_Click()
    Debug.Print pvReplaceDevice("\Device\HarddiskVolume1\aaa.txt")
End Sub

Private Function pvReplaceDevice(sPath As String) As String
    Dim sDrive          As String
    Dim sDevice         As String
    Dim lIdx            As Long

    For lIdx = 0 To 25
        sDrive = Chr$(65 + lIdx) & ":"
        sDevice = Space(1000)
        If QueryDosDevice(sDrive, sDevice, Len(sDevice)) <> 0 Then
            sDevice = Left$(sDevice, InStr(sDevice, Chr$(0)) - 1)
'            Debug.Print sDrive; "="; sDevice
            If LCase$(Left$(sPath, Len(sDevice))) = LCase$(sDevice) Then
                pvReplaceDevice = sDrive & Mid$(sPath, Len(sDevice) + 1)
                Exit Function
            End If
        End If
    Next
    pvReplaceDevice = sPath
End Function
选项显式
私有声明函数QueryDosDevice Lib“kernel32”别名“QueryDosDeviceA”(ByVal lpDeviceName为字符串,ByVal lpTargetPath为字符串,ByVal ucchMax为长)为长
专用子命令1_Click()
调试。打印pvReplaceDevice(“\Device\HarddiskVolume1\aaa.txt”)
端接头
专用函数pvReplaceDevice(sPath作为字符串)作为字符串
像弦一样暗的字
将设备设置为字符串
暗淡的lIdx和长的一样
对于lIdx=0到25
sDrive=Chr$(65+lIdx)和“:”
设备=空间(1000)
如果QueryDosDevice(sDrive、sDevice、Len(sDevice))为0,则
sDevice=Left$(sDevice,InStr(sDevice,Chr$(0))-1)
'调试.打印sDrive;"="; 电子设备
如果LCase$(左$(sPath,Len(sDevice))=LCase$(sDevice),则
pvReplaceDevice=sDrive&Mid$(sPath,Len(sDevice)+1)
退出功能
如果结束
如果结束
下一个
pvReplaceDevice=sPath
端函数
试试这个

Option Explicit

Private Declare Function QueryDosDevice Lib "kernel32" Alias "QueryDosDeviceA" (ByVal lpDeviceName As String, ByVal lpTargetPath As String, ByVal ucchMax As Long) As Long

Private Sub Command1_Click()
    Debug.Print pvReplaceDevice("\Device\HarddiskVolume1\aaa.txt")
End Sub

Private Function pvReplaceDevice(sPath As String) As String
    Dim sDrive          As String
    Dim sDevice         As String
    Dim lIdx            As Long

    For lIdx = 0 To 25
        sDrive = Chr$(65 + lIdx) & ":"
        sDevice = Space(1000)
        If QueryDosDevice(sDrive, sDevice, Len(sDevice)) <> 0 Then
            sDevice = Left$(sDevice, InStr(sDevice, Chr$(0)) - 1)
'            Debug.Print sDrive; "="; sDevice
            If LCase$(Left$(sPath, Len(sDevice))) = LCase$(sDevice) Then
                pvReplaceDevice = sDrive & Mid$(sPath, Len(sDevice) + 1)
                Exit Function
            End If
        End If
    Next
    pvReplaceDevice = sPath
End Function
选项显式
私有声明函数QueryDosDevice Lib“kernel32”别名“QueryDosDeviceA”(ByVal lpDeviceName为字符串,ByVal lpTargetPath为字符串,ByVal ucchMax为长)为长
专用子命令1_Click()
调试。打印pvReplaceDevice(“\Device\HarddiskVolume1\aaa.txt”)
端接头
专用函数pvReplaceDevice(sPath作为字符串)作为字符串
像弦一样暗的字
将设备设置为字符串
暗淡的lIdx和长的一样
对于lIdx=0到25
sDrive=Chr$(65+lIdx)和“:”
设备=空间(1000)
如果QueryDosDevice(sDrive、sDevice、Len(sDevice))为0,则
sDevice=Left$(sDevice,InStr(sDevice,Chr$(0))-1)
'调试.打印sDrive;"="; 电子设备
如果LCase$(左$(sPath,Len(sDevice))=LCase$(sDevice),则
pvReplaceDevice=sDrive&Mid$(sPath,Len(sDevice)+1)
退出功能
如果结束
如果结束
下一个
pvReplaceDevice=sPath
端函数

如果您想高效使用API函数,请创建一个类-“DiskDevice”


这样,您就不必多次调用API函数,只需执行集合查找。

如果您想要高效地使用API函数,请创建一个类-“DiskDevice”


这样,你不必多次调用API函数——你只需要做一个集合查找。

如果这个答案对你有帮助,@ USE75 7321,那么请考虑把它标记为被接受的答案,这样其他人将来可能更容易找到它。这也是一个礼貌的方式来感谢回答你的问题的人帮助你。如果这个答案对你有帮助,@ USER77321,那么请考虑将它标记为被接受的答案,以便其他人在将来更容易找到它。这也是一种礼貌的方式来感谢回答你问题的人帮助了你。
Set m_oDiskDevice = New DiskDevice

...

sMyPath = m_oDiskDevice.GetFilePathFromDevicePath("\Device\HarddiskVolume1\programfile\explorer.exe")