如何建立快捷方式以及更改其中的某些参数(在任何文件夹中)?

netbugs 2000-05-31 02:31:00
听说可以用IShellLink接口,但我不知怎样实现。如果IShellLink在VB中不能用,那么如何调用系统API来实现,不用VB做安装盘中的dll。希望能给出示例代码,多谢了!
...全文
322 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
netbugs 2000-07-08
  • 打赏
  • 举报
回复
With SHFileOp
.wFunc = FO_COPY
.pFrom = sSource
.pTo = sDestination
.fFlags = FOF_SILENT Or FOF_NOCONFIRMATION
End With

'and perform the copy
Call SHFileOperation(SHFileOp)
shfileoperation是"Shell32.dll"中的文件操作函数,shfileop.wfunc是文件操作的功能,.wfunc=fo_copy不就是复制文件吗?
Chen_Lin 2000-06-26
  • 打赏
  • 举报
回复
不理解您的意思.
-----------------------------
用几个小时拨号上网找到的资料落了个"只是复制"的名声......
netbugs 2000-06-26
  • 打赏
  • 举报
回复
谢谢chen_lin,但这么多的代码好象只是复制,我想要的是给出命令行、图标等参数就可建立快捷方式。如果不行,直接用文件访问方式来建立或读写lnk文件也行(源代码)。
Chen_Lin 2000-06-11
  • 打赏
  • 举报
回复
你说的对,CSDN上回答的都是用安装盘中的DLL,
应该有API函数调用,见下:
-----------------------以下再BAS中定义-------------------
Public Const ERROR_SUCCESS As Long = 0
Public Const CSIDL_DESKTOP As Long = &H0
Public Const CSIDL_PROGRAMS As Long = &H2
Public Const CSIDL_STARTMENU As Long = &HB
Public Const CSIDL_DESKTOPDIRECTORY As Long = &H10

Public Const FO_COPY As Long = &H2
Public Const FOF_SILENT As Long = &H4
Public Const FOF_RENAMEONCOLLISION As Long = &H8
Public Const FOF_NOCONFIRMATION As Long = &H10

Public Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAborted As Boolean
hNameMaps As Long
sProgress As String
End Type

Public Declare Function SHFileOperation Lib "shell32.dll" _
Alias "SHFileOperationA" _
(lpFileOp As SHFILEOPSTRUCT) As Long

Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" _
(ByVal pidl As Long, _
ByVal pszPath As String) As Long

Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" _
(ByVal hwndOwner As Long, _
ByVal nFolder As Long, _
pidl As Long) As Long

Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)


Public Sub CreateDesktopLink(sSource As String, sDestination As String)

'working variables
Dim sFiles As String
Dim SHFileOp As SHFILEOPSTRUCT

'terminate passed strings with a null
sSource = sSource & Chr$(0)
sDestination = sDestination & Chr$(0)

'set up the options
With SHFileOp
.wFunc = FO_COPY
.pFrom = sSource
.pTo = sDestination
.fFlags = FOF_SILENT Or FOF_NOCONFIRMATION
End With

'and perform the copy
Call SHFileOperation(SHFileOp)

End Sub


Public Function GetSpecialFolder(hWnd As Long, CSIDL As Long) As String

Dim pidl As Long
Dim pos As Long
Dim sPath As String

'fill the pidl with the specified folder item
If SHGetSpecialFolderLocation(hWnd, CSIDL, pidl) = ERROR_SUCCESS Then

'initialize & get the path
sPath = Space$(260)

If SHGetPathFromIDList(ByVal pidl, ByVal sPath) Then

'has a null?
pos = InStr(sPath, Chr$(0))

'strip it
If pos Then

'return folder
GetSpecialFolder = Left$(sPath, pos - 1)

End If

Call CoTaskMemFree(pidl)

End If

End If

End Function
----------------------------以下在主程序中----------------
Dim sDeskPath As String
Dim sStartPath As String
Dim sProgramsLinkPath As String

'path to the current user's Programs folder
sStartPath = GetSpecialFolder(Me.hWnd, CSIDL_PROGRAMS)

'path to the current user's Desktop folder
sDeskPath = GetSpecialFolder(Me.hWnd, CSIDL_DESKTOPDIRECTORY)

'from Programs, path to application link
'and application link name
sProgramsLinkPath = "\MyApp\MyApp.lnk"

'create the desktop link with the values
Call CreateDesktopLink(sStartPath & sProgramsLinkPath, sDeskPath)

----------------------结束--------------------------------------
netbugs 2000-06-05
  • 打赏
  • 举报
回复
你们所说的的Dll都是安装盘中的,有没有其他的API函数,不是vb自带的?
tanhl 2000-06-01
  • 打赏
  • 举报
回复
生成快捷方式的示例代码可以在VB5或VB6中的安装程序示例中找到,具体目录为:

SetupKit/Setup1/Setup1.vbp

你可以打开此工程文件,可找到有关声明。
Chen_Lin 2000-06-01
  • 打赏
  • 举报
回复
http://expert.csdn.net/Topic/6924.shtm
Un1 2000-05-31
  • 打赏
  • 举报
回复
这是申明于 Setup1.vbp 中的代码,去看看。

Declare Function OSfCreateShellLink Lib "vb6stkit.dll" Alias "fCreateShellLink" (ByVal lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal lpstrLinkPath As String, ByVal lpstrLinkArguments As String, ByVal fPrivate As Long, ByVal sParent As String) As Long

7,759

社区成员

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

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