我需要在Windows CE上通过VBA获取USB驱动器的名称。
在Win 7上,Usb Drive被称为“我的拇指驱动器”,在获胜CE上我将其视为“硬盘2”。有什么方法可以读取真正的Thumb名称并将其存储在变量中吗?
FCE(文件系统对象)在Win CE上不可用。
----------------------编辑------------------------ ---
另一种方法是在Win CE上的VBA中恢复txt文件的修改日期。 (日期文件已创建或保存,未被访问。)
答案 0 :(得分:2)
试试这个。在Sub Sample()
Option Explicit
Private Declare Function OpenFile Lib "kernel32" _
(ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, _
ByVal wStyle As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function GetFileTime Lib "kernel32" _
(ByVal hFile As Long, lpCreationTime As FILETIME, _
lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
Private Declare Function FileTimeToSystemTime Lib _
"kernel32" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long
Private Const OF_READ = &H0
Private Const OFS_MAXPATHNAME = 128
Private Type OFSTRUCT
cBytes As Byte
fFixedDisk As Byte
nErrCode As Integer
Reserved1 As Integer
Reserved2 As Integer
szPathName(OFS_MAXPATHNAME) As Byte
End Type
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Sub Sample()
Debug.Print GetFileCreatedDateAndTime("c:\Sample.txt")
End Sub
Private Function GetFileCreatedDateAndTime(sFile As String) As String
Dim hFile As Long, rval As Long
Dim buff As OFSTRUCT
Dim f1Time As FILETIME, f2Time As FILETIME, f3Time As FILETIME
Dim stime As SYSTEMTIME
GetFileCreatedDateAndTime = "Unable To retrieve details"
hFile = OpenFile(sFile, buff, OF_READ)
If hFile Then
rval = GetFileTime(hFile, f1Time, f2Time, f3Time)
rval = FileTimeToSystemTime(f1Time, stime)
GetFileCreatedDateAndTime = _
"Created on " & _
stime.wDay & "-" & stime.wMonth & "-" & stime.wYear & _
Chr(13) & _
"Created at " & _
stime.wHour & ":" & stime.wMinute & ":" & stime.wSecond
End If
rval = CloseHandle(hFile)
End Function