我这里有几个程序,首先用来判断操作系统,不同的操作系统的位置不一样,是针对读取硬盘快捷方式的,不是开始菜单的,作为参考'判断操作系统 Public Declare Function GetVersionExA Lib "kernel32" _ (lpVersionInformation As OSVERSIONINFO) As Integer
Public Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long szCSDVersion As String * 128 End Type
Public Function getVersion() As String Dim osinfo As OSVERSIONINFO Dim retvalue As Integer
Select Case .dwMinorVersion Case 0 getVersion = "Windows 95" Case 10 getVersion = "Windows 98" Case 90 getVersion = "Windows Mellinnium" End Select
Case 2 Select Case .dwMajorVersion Case 3 getVersion = "Windows NT 3.51" Case 4 getVersion = "Windows NT 4.0" Case 5 If .dwMinorVersion = 0 Then getVersion = "Windows 2000" Else getVersion = "Windows XP" End If End Select
Case Else getVersion = "Failed" End Select
End With End Function'根据操作系统可以找到开始菜单的文件夹,然后遍历每一个文件 Sub scan(a As String) Dim filename As String Dim nd As Integer Dim fold() As String Dim n As Integerfilename = Dir(a, vbDirectory) Do While filename <> "" If filename <> "." And filename <> ".." Then If GetAttr(a & filename) = vbDirectory Then nd = nd + 1 ReDim Preserve fold(nd) fold(nd) = a & filename ' List2.AddItem (a & filename) TreeView1.Nodes.Add a, tvwChild, a & filename & "\", filename, 1, 2 End If End If filename = Dir DoEvents Loopfilename = Dir(a) Do While filename <> "" ' List1.AddItem (a & filename) TreeView1.Nodes.Add a, tvwChild, a & filename, filename, 3, 4 filename = Dir LoopFor n = 1 To nd Call scan(fold(n) & "\") Next End SubPrivate Sub Command1_Click() TreeView1.ImageList = ImageList1 Dim vcmpath As String 'vcmpath = App.Path & "vvv\" vcmpath = "c:\windows\" TreeView1.Nodes.Add , , vcmpath, "VCM", 1, 2 Call scan(vcmpath) End Sub Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node) Text1.Text = Node.Key End Sub'得到每个文件之后可以用下面的方法来分析快捷方式 Option Explicit Dim iwSH As New IWshRuntimeLibrary.IWshShell_Class Dim iwSC As IWshRuntimeLibrary.IWshShortcut_Class Dim iwCreateLNK As IWshRuntimeLibrary.IWshShortcut_Class Private Sub cmdCreateLNK_Click() Set iwCreateLNK = iwSH.CreateShortcut("d:\yy.lnk") 'd:\yy.lnk为要创建的快捷方式 iwCreateLNK.TargetPath = "D:\Program Files\OWN\OWN.exe" '"D:\Program Files\OWN\OWN.exe" 为该快捷方式所指的目标文件 iwCreateLNK.IconLocation = "D:\Program Files\OWN\OWN.exe" '设置该快捷方式的图标 iwCreateLNK.Save End SubPrivate Sub cmdGetLNKInfo_Click()
Set iwSC = iwSH.CreateShortcut("c:\Foxmail.lnk ") msgbox iwSC.targetPath '获取快捷方式的目标文件 '另外还有其它属性保存着该快捷方式的信息 End Sub 另外:如果找不到Windows Script Host Object Model 的引用请直接在引用中单击“浏览”,并将文件类型改为*.OCX,找到该文件:Wshom.ocx 即可引用它了。 ============================================== Dim iwSH As New IWshRuntimeLibrary.IWshShell_Class Dim iwSC As IWshRuntimeLibrary.IWshShortcut_Class Dim s As String s = Dir("c:\windows\recent\*.*") While s <> "" s = Dir()
Set iwSC = iwSH.CreateShortcut("c:\windows\recent\" + s) MsgBox iwSC.TargetPath '获取快捷方式的目标文件 Exit Sub
Public Declare Function GetVersionExA Lib "kernel32" _
(lpVersionInformation As OSVERSIONINFO) As Integer
Public Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type
Public Function getVersion() As String
Dim osinfo As OSVERSIONINFO
Dim retvalue As Integer
osinfo.dwOSVersionInfoSize = 148
osinfo.szCSDVersion = Space$(128)
retvalue = GetVersionExA(osinfo)
With osinfo
Select Case .dwPlatformId
Case 1
Select Case .dwMinorVersion
Case 0
getVersion = "Windows 95"
Case 10
getVersion = "Windows 98"
Case 90
getVersion = "Windows Mellinnium"
End Select
Case 2
Select Case .dwMajorVersion
Case 3
getVersion = "Windows NT 3.51"
Case 4
getVersion = "Windows NT 4.0"
Case 5
If .dwMinorVersion = 0 Then
getVersion = "Windows 2000"
Else
getVersion = "Windows XP"
End If
End Select
Case Else
getVersion = "Failed"
End Select
End With
End Function'根据操作系统可以找到开始菜单的文件夹,然后遍历每一个文件
Sub scan(a As String)
Dim filename As String
Dim nd As Integer
Dim fold() As String
Dim n As Integerfilename = Dir(a, vbDirectory)
Do While filename <> ""
If filename <> "." And filename <> ".." Then
If GetAttr(a & filename) = vbDirectory Then
nd = nd + 1
ReDim Preserve fold(nd)
fold(nd) = a & filename
' List2.AddItem (a & filename)
TreeView1.Nodes.Add a, tvwChild, a & filename & "\", filename, 1, 2
End If
End If
filename = Dir
DoEvents
Loopfilename = Dir(a)
Do While filename <> ""
' List1.AddItem (a & filename)
TreeView1.Nodes.Add a, tvwChild, a & filename, filename, 3, 4
filename = Dir
LoopFor n = 1 To nd
Call scan(fold(n) & "\")
Next
End SubPrivate Sub Command1_Click()
TreeView1.ImageList = ImageList1
Dim vcmpath As String
'vcmpath = App.Path & "vvv\"
vcmpath = "c:\windows\"
TreeView1.Nodes.Add , , vcmpath, "VCM", 1, 2
Call scan(vcmpath)
End Sub
Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
Text1.Text = Node.Key
End Sub'得到每个文件之后可以用下面的方法来分析快捷方式
Option Explicit
Dim iwSH As New IWshRuntimeLibrary.IWshShell_Class
Dim iwSC As IWshRuntimeLibrary.IWshShortcut_Class
Dim iwCreateLNK As IWshRuntimeLibrary.IWshShortcut_Class
Private Sub cmdCreateLNK_Click()
Set iwCreateLNK = iwSH.CreateShortcut("d:\yy.lnk") 'd:\yy.lnk为要创建的快捷方式
iwCreateLNK.TargetPath = "D:\Program Files\OWN\OWN.exe" '"D:\Program Files\OWN\OWN.exe"
为该快捷方式所指的目标文件
iwCreateLNK.IconLocation = "D:\Program Files\OWN\OWN.exe" '设置该快捷方式的图标
iwCreateLNK.Save
End SubPrivate Sub cmdGetLNKInfo_Click()
Set iwSC = iwSH.CreateShortcut("c:\Foxmail.lnk
")
msgbox iwSC.targetPath '获取快捷方式的目标文件 '另外还有其它属性保存着该快捷方式的信息
End Sub
另外:如果找不到Windows Script Host Object Model
的引用请直接在引用中单击“浏览”,并将文件类型改为*.OCX,找到该文件:Wshom.ocx 即可引用它了。
==============================================
Dim iwSH As New IWshRuntimeLibrary.IWshShell_Class
Dim iwSC As IWshRuntimeLibrary.IWshShortcut_Class
Dim s As String
s = Dir("c:\windows\recent\*.*")
While s <> ""
s = Dir()
Set iwSC = iwSH.CreateShortcut("c:\windows\recent\" + s) MsgBox iwSC.TargetPath '获取快捷方式的目标文件
Exit Sub
Wend
End Sub