如何用API读取快捷方式的具体内容

yuliang0828 2003-03-14 10:04:09
各位高手,请问如何用API来读取快捷方式的具体内容,如:快捷键,目标等。
...全文
189 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuliang0828 2003-03-24
  • 打赏
  • 举报
回复
多谢!
litsnake1 2003-03-24
  • 打赏
  • 举报
回复
up
fbmsf 2003-03-14
  • 打赏
  • 举报
回复
这个问题其实有不少解决方法,可以直接用API,也可以用vb中的dll。不过
API使用麻烦,VB中的dll则随版本的不同而使用有别。其实VB6的光盘里有一个
更好的解决方案。

1.在VB6光盘中查找shelllnk目录,打开其中的shelllnk.vbp工程,将其编译成
shelllnk.dll。这个dll中即包括了建立及解读lnk的所有函数。

2.在工程中加入对该dll的引用。

3.该dll中与快捷方式有关的主要有cShelllnk对象和它的三个方法:
CreateShellLink, GetShellLinkInfo, GetSystemFolderPath

4.解读lnk的示例:
Dim lnkObj As New cShellLink
Dim ExeFile As String, WorkDir As String, ExeArgs As String
Dim IconFile As String, IconIdx As Long, ShowCmd As Long

lnkObj.GetShellLinkInfo App.Path & "\LnkDemo.lnk", ExeFile, _
WorkDir, ExeArgs, IconFile, IconIdx, ShowCmd

Cls
Print "Exefile = ", ExeFile
Print "WorkDir = ", WorkDir
Print "ExeArgs = ", ExeArgs
Print "IconFile = ", IconFile
Print "IconIdx = ", IconIdx
Print "ShowCmd = ", ShowCmd
各个参数的具体含义请网友们自行验证。

5.建立lnk的示例:
Dim lnkObj as New cShellLink
Dim ExeFile As String, WorkDir As String, ExeArgs As String
Dim IconFile As String, IconIdx As Long, ShowCmd As Long

lnkObj.CreateShellLink pathname, ExeFile, WorkDir, ExeArgs, _
IconFile, IconIdx, ShowCmd

yefm 2003-03-14
  • 打赏
  • 举报
回复
up
用户 昵称 2003-03-14
  • 打赏
  • 举报
回复
some code

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 Sub



Private 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

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧