如何用VB给指定文件创建桌面快捷方式

[复制链接]
查看11 | 回复2 | 2016-1-7 22:54:30 | 显示全部楼层 |阅读模式
Private 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
Public Function CreatLinkAtDesktop(strName As String, strFile As String, Optional strPro As String) As Boolean
CreatLinkAtDesktop = True
Dim lReturn
As Long
'win2000下
lReturn = OSfCreateShellLink("..\..\桌面", strUnQuoteString(strName), strUnQuoteString(strFile), strPro & vbNullChar, True, "$(Programs)")
If lReturn Then Exit Function
'win98下
lReturn = OSfCreateShellLink("..\..\Desktop", strUnQuoteString(strName), strUnQuoteString(strFile), strPro & vbNullChar, True, "$(Programs)")
If lReturn Then Exit Function
CreatLinkAtDesktop = FalseEnd FunctionPublic Function strUnQuoteString(ByVal strQuotedString As String)'' This routine tests to see if strQuotedString is wrapped in quotation' marks, and, if so, remove them.'
strQuotedString = Trim(strQuotedString)
If Mid$(strQuotedString, 1, 1) = gstrQUOTE And Right$(strQuotedString, 1) = gstrQUOTE Then
'
' It's quoted.
Get rid of the quotes.
'
strQuotedString = Mid$(strQuotedString, 2, Len(strQuotedString) - 2)
End If
strUnQuoteString = strQuotedStringEnd FunctionPrivate Sub Command1_Click()'CreatLinkAtDesktop "notepad.exe", "c:\Windows\system32\notepad.exe"CreatLinkAtDesktop "娱乐程序.exe ", "写娱乐程序.exe所在的文件全路径"End Sub
回复

使用道具 举报

千问 | 2016-1-7 22:54:30 | 显示全部楼层
创建快捷方式-例子Dim nPath As String, sh, ShortCut
'获取当前用户的桌面目录Set sh = CreateObject("wscript.shell")nPath = sh.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Desktop")If Right(nPath, 1)"" Then nPath = nPath & "\"
ShortF = nPath & "文本文档.lnk"'快捷方式名称Set ShortCut = sh.CreateShortcut(ShortF) '创建一个快捷方式对象ShortCut.TargetPath = "C:\a.txt"'快捷方式指向的目标,可以是任意文件ShortCut.Save'保存快捷方式
回复

使用道具 举报

千问 | 2016-1-7 22:54:30 | 显示全部楼层
用API函数:fcreatshelllink
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行