如何用Windows自带的API来创建快捷方式?带参数的
想自动创建QQ的快捷启动,需要带参数,网上提供了一种
Option Explicit
Public Sub mShellLnk(ByVal LnkName As String, IconFileIconIndex As String, ByVal FilePath As String, Optional ByVal FileName As String, Optional ByVal HookKey As String = " ", Optional ByVal StrRemark As String = " ", Optional ByVal strDesktop As String = " ")
Dim WshShell As Object, WScript As Object, oShellLink As Object
Set WshShell = CreateObject( "WScript.Shell ")
If strDesktop = " " Then strDesktop = WshShell.SpecialFolders( "Desktop ") '桌面路径
If UCase(Right(LnkName, 4)) = ".LNK " Then
Set oShellLink = WshShell.CreateShortcut(strDesktop & "\ " & LnkName) '创建快捷方式,参数为路径和名称
Else
Set oShellLink = WshShell.CreateShortcut(strDesktop & "\ " & LnkName & ".lnk ")
End If
oShellLink.TargetPath = FilePath & "\ " & FileName
oShellLink.WindowStyle = 1 '风格
oShellLink.Hotkey = HookKey '热键
oShellLink.IconLocation = IconFileIconIndex '图标
oShellLink.Description = StrRemark '快捷方式备注内容
oShellLink.WorkingDirectory = FilePath '源文件所在目录
oShellLink.Save '保存创建的快捷方式
Set WshShell = Nothing
Set oShellLink = Nothing
End Sub
的方法,可是这个方法,我做不到带参数。
谁有别的方法做一个带参数快捷方式的方法呢?
只要成功,就全给分
[解决办法]
看了一下这个WshShortcut对象,它有一个叫 "Arguments "的属性......
于是给你小改了一下:
Public Sub mShellLnk(ByVal LnkName As String, IconFileIconIndex As String, ByVal FilePath As String, Optional ByVal FileName As String, Optional ByVal StrArg As String, Optional ByVal HookKey As String = " ", Optional ByVal StrRemark As String = " ", Optional ByVal strDesktop As String = " ")
Dim WshShell As Object, WScript As Object, oShellLink As Object
Set WshShell = CreateObject( "WScript.Shell ")
If strDesktop = " " Then strDesktop = WshShell.SpecialFolders( "Desktop ") '桌面路径
If UCase(Right(LnkName, 4)) = ".LNK " Then
Set oShellLink = WshShell.CreateShortcut(strDesktop & "\ " & LnkName) '创建快捷方式,参数为路径和名称
Else
Set oShellLink = WshShell.CreateShortcut(strDesktop & "\ " & LnkName & ".lnk ")
End If
oShellLink.TargetPath = FilePath & "\ " & FileName
oShellLink.Arguments = StrArg
oShellLink.WindowStyle = 1 '风格
oShellLink.Hotkey = HookKey '热键
oShellLink.IconLocation = IconFileIconIndex '图标
oShellLink.Description = StrRemark '快捷方式备注内容
oShellLink.WorkingDirectory = FilePath '源文件所在目录
oShellLink.Save '保存创建的快捷方式
Set WshShell = Nothing
Set oShellLink = Nothing
End Sub
例子:
mShellLnk "TestLnk ", "notepad.exe ", "C:\windows\ ", "notepad.exe ", "test.txt "
PS:
其实LZ自己看一下,也会发现啊,也就那么几个成员....