-
mShellLnk "计算器", "c:\windows\system32\calc.exe"
Public Sub mShellLnk(ByVal LnkName As String, ByVal FilePath As String, Optional ByVal StrArg As String, Optional ByVal IconFileIconIndex As String = vbNullString, Optional ByVal HookKey As String = "", Optional ByVal StrRemark As String = "")
'调用说明:
'
'LnkName = 快捷方式文件名,如果无路径则自动新建到桌面;无后缀名(.lnk)会自动补齐.
'FilePath = 目标文件名,全路径.
'StrArg = 参数,可选.
'IconFileIconIndex = 图标所在库及索引,由逗号分隔,可选.如: "c:\windows\system32\notepad.exe,0"
'HookKey = 热键,值未知,可选.
'StrRemark = 备注,可选.
'
Dim WshShell As Object, oShellLink As Object, strDesktop As StringSet WshShell = CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop") '桌面路径
If UCase$(Right$(LnkName, 4)) <> ".LNK" Then
LnkName = LnkName & ".lnk"
End IfIf InStr(1, LnkName, "\", vbTextCompare) = 0 Then '如果不包含全路径,则在桌面创建快捷方式
Set oShellLink = WshShell.CreateShortcut(strDesktop & "\" & LnkName)
Else '否则在指定位置创建
Set oShellLink = WshShell.CreateShortcut(LnkName)
End IfoShellLink.TargetPath = FilePath
oShellLink.Arguments = StrArg
oShellLink.WindowStyle = 1 '风格
oShellLink.Hotkey = HookKey '热键If IconFileIconIndex = vbNullString Then '图标
oShellLink.IconLocation = FilePath & ",0" '默认使用目标文件图标
Else
oShellLink.IconLocation = IconFileIconIndex
End IfoShellLink.Description = StrRemark '快捷方式备注内容
oShellLink.WorkingDirectory = Mid$(FilePath, 1, InStrRev(FilePath, "\")) '源文件所在目录
oShellLin
VB 创建快捷方式函数(可带参数)
最新推荐文章于 2020-10-16 09:29:46 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)
调用示例: