1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const HKEY_USERS = &H80000003
Private Const HKEY_PERFORMANCE_DATA = &H80000004
Const REG_SZ = 1 ' Unicode nul terminated string
Const REG_BINARY = 3 ' Free form binary
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Function ExtractFilePath(ByVal f As String, Optional ByVal EndSlash As Boolean = True) As String
Dim Splitf() As String, i As Integer
If InStr(f, "\") = 0 Then
ExtractFilePath = ""
Exit Function
End If
Splitf = Split(f, "\")
For i = 0 To UBound(Splitf) - 1
ExtractFilePath = ExtractFilePath & Splitf(i) & "\"
Next i
If Not EndSlash Then ExtractFilePath = Left(ExtractFilePath, Len(ExtractFilePath) - 1)
End Function
Private Sub Form_Load()
Dim Objset
Dim Obj
Dim SID As String
Set Objset = GetObject("winmgmts:{impersonationLevel=impersonate}"). _
InstancesOf("Win32_Account")
On Local Error Resume Next
For Each Obj In Objset
If Obj.Name = Environ("UserName") Then
SID = Obj.SID
Exit For
End If
Next
Dim lResult As Long, lValueType As Long, lDataBufSize As Long, Ret As Long
Dim strBuf As String, strBuf2 As String
lResult = RegOpenKey(HKEY_USERS, SID & "\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\OpenSaveMRU\*", Ret)
lResult = RegQueryValueEx(Ret, "MRUList", 0, REG_SZ, ByVal 0, lDataBufSize)
If lResult = 0 Then
strBuf = String(lDataBufSize, Chr$(0))
lResult = RegQueryValueEx(Ret, "MRUList", 0, 0, ByVal strBuf, lDataBufSize)
If lResult = 0 Then
lResult = RegQueryValueEx(Ret, Left$(strBuf, 1), 0, REG_SZ, ByVal 0, lDataBufSize)
strBuf2 = String(lDataBufSize, Chr$(0))
lResult = RegQueryValueEx(Ret, Left$(strBuf, 1), 0, 0, ByVal strBuf2, lDataBufSize)
End If
End If
MsgBox ExtractFilePath(strBuf2)
End Sub |
Partager