vb创建快捷方式代码
作者:未知 文章ID:9381 浏览:
调用:
mShellLnk "Internet Explorer", "C:\Program Files\Internet Explorer\iexplore.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 String
Set WshShell = CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
If UCase(Right(LnkName, 4)) <> ".LNK" Then
LnkName = LnkName & ".lnk"
End If
If InStr(1, LnkName, "\", vbTextCompare) = 0 Then
Set oShellLink = WshShell.CreateShortcut(strDesktop & "\" & LnkName)
Else
Set oShellLink = WshShell.CreateShortcut(LnkName)
End If
oShellLink.TargetPath = FilePath
oShellLink.Arguments = StrArg
oShellLink.WindowStyle = 1
oShellLink.Hotkey = HookKey
If IconFileIconIndex = vbNullString Then
oShellLink.IconLocation = FilePath & ",0"
Else
oShellLink.IconLocation = IconFileIconIndex
End If
oShellLink.Description = StrRemark
oShellLink.WorkingDirectory = Mid(FilePath, 1, InStrRev(FilePath, "\"))
oShellLink.Save
Set WshShell = Nothing
Set oShellLink = Nothing
End Sub