![]() |
|
提问:VB读取收藏夹中的URL
如何读取收藏夹中的文件,到菜单上去。就像IE中的收藏菜单一样。收藏夹位置在注册表中的位置,我已经找到。HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders下的Favorites键值。
使用以下方法即可读取该键值中的内容,
Dim w As Object
Set w = CreateObject("wscript.shell")
MsgBox w.regread("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Favorites")
现在的问题是,我不会读取文件到动态菜单中,以及读取文件夹中的文件。
回答:
先建一个“收藏”菜单,再在其下建一个子菜单 标题:(空白),名称:Fmenu, 索引:0
然后在Form1中输入下列代码就行了.我测试过的.
Dim fPath As String
Private Sub Fmenu_Click(Index As Integer)
Shell "C:\Program Files\Internet Explorer\iexplore.exe " & fPath & "\" & Fmenu(Index).Caption & ".url"
End Sub
Private Sub Form_Load()
Dim w As Object, Files As String
Set w = CreateObject("wscript.shell")
fPath = w.regread("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Favorites")
Files = Dir(fPath & "\*.url", vbNormal)
For i = 0 To 1000
If Files <> "" Then
If i > 0 Then Load Fmenu(i)
Fmenu(i).Visible = True
Fmenu(i).Caption = Left(Files, Len(Files) - 4)
Else
Exit For
End If
Files = Dir
Next
End Sub